Symfony 4 & Sonata Admin 3 警告:spl_object_hash() 期望参数 1 是对象,给定字符串



我正在使用Symfony 4&Sonata Admin 3并试图为我的预订实体建立管理员。预订与乘客有一对一的关系。预期显示预订表格,但在提交时显示以下消息...

Warning: spl_object_hash() expects parameter 1 to be object, string given

预先感谢您的任何帮助。

bookingadmin class

<?php
namespace AppAdmin;
use AppEntityMeetingLocation;
use AppEntityPassenger;
use SonataAdminBundleAdminAbstractAdmin;
use SonataAdminBundleFormFormMapper;
use SonataAdminBundleDatagridDatagridMapper;
use SonataAdminBundleDatagridListMapper;
use SonataAdminBundleFormTypeCollectionType;
use SonataAdminBundleFormTypeModelListType;
use SonataAdminBundleFormTypeModelType;
use SonataAdminBundleShowShowMapper;
use SonataFormTypeDateTimePickerType;
use SymfonyComponentFormExtensionCoreTypeDateType;
class BookingAdmin extends AbstractAdmin
{
    protected $baseRoutePattern = 'booking';
    protected $baseRouteName = 'booking';
    public function getNewInstance()
    {
        $instance = parent::getNewInstance();
        return $instance;
    }
    protected $datagridValues = array(
        // display the first page (default = 1)
        '_page' => 1,
        // reverse order (default = 'ASC')
        '_sort_order' => 'DESC',
        // name of the ordered field (default = the model's id field, if any)
        //          '_sort_by' => 'updatedAt',
    );
    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->add('flightdate', DateType::class, [
                            'widget' => 'single_text',
//                            'html5' => false,
                            'attr' => ['class' => 'js-datepicker'],])
            ->add('meetingTime')
            ->add('flight')
            ->add('meetingLocation')
            ->add('contactinfo')
            ->add('passengers', CollectionType::class, array('allow_add' => true))
            ->add('notes')
        ;
    }
    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
    {
        $datagridMapper
            ->add('contactinfo')
            ->add('flightdate')
            ->add('flight')
            ->add('passengers')
            ->add('meetingTime')
        ;
    }
    protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper
            ->addIdentifier('id')
            ->add('status')
            ->add('contactinfo')
            ->add('flightdate')
            ->add('flight')
            ->add('passengers')
            ->add('meetingTime')
            ->add('meetingLocation')
            ->add('_action', null, array(
                'actions' => array(
                    'edit' => [],
                    'delete' => [],
                )
            ))
        ;
    }
    protected function configureShowFields(ShowMapper $showMapper)
    {
        $showMapper
            ->add('status')
            ->add('contactinfo')
            ->add('flightdate')
            ->add('flight')
            ->add('passengers')
            ->add('meetingTime')
            ->add('meetingLocation')
        ;
    }
}

Pressengeradmin类

<?php
namespace AppAdmin;
use SonataAdminBundleAdminAbstractAdmin;
use SonataAdminBundleFormFormMapper;
use SonataAdminBundleDatagridDatagridMapper;
use SonataAdminBundleDatagridListMapper;
use SonataAdminBundleShowShowMapper;
class PassengerAdmin extends AbstractAdmin
{
    protected $baseRoutePattern = 'passenger';
    protected $baseRouteName = 'passenger';
    public function getNewInstance()
    {
        $instance = parent::getNewInstance();
        return $instance;
    }
    protected $datagridValues = array(
        // display the first page (default = 1)
        '_page' => 1,
        // reverse order (default = 'ASC')
        '_sort_order' => 'DESC',
        // name of the ordered field (default = the model's id field, if any)
        //          '_sort_by' => 'updatedAt',
    );
    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->with('User', array('class' => 'col-md-6'))
            ->add('name')
            ->end()
        ;
    }
    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
    {
        $datagridMapper
            ->add('name')
        ;
    }
    protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper
            ->addIdentifier('name')
            ->add('booking')
            ->add('_action', null, array(
                'actions' => array(
                    'edit' => [],
                    'delete' => [],
                )
            ))
        ;
    }
    protected function configureShowFields(ShowMapper $showMapper)
    {
        $showMapper
            ->add('name')
        ;
    }
}

预订实体类

<?php
namespace AppEntity;
use DoctrineORMMapping as ORM;
use GedmoMappingAnnotation as Gedmo;
use SymfonyComponentValidatorConstraints as Assert;
/**
 * @ORMEntity(repositoryClass="AppRepositoryBookingRepository")
 * @ORMTable(name="booking")
 * @GedmoSoftDeleteable(fieldName="deleted")
 */
class Booking
{
    const STATUS_NEW = 1;
    const STATUS_CONFIRMED = 2;
    const STATUS_PAYMENT_PART = 3;
    const STATUS_PAYMENT_FULL = 4;
    public function __construct()
    {
        $this->passengers = new DoctrineCommonCollectionsArrayCollection();
        $this->status = self::STATUS_NEW;
    }

    /**
     * @ORMColumn(type="integer")
     * @ORMId
     * @ORMGeneratedValue(strategy="AUTO")
     */
     private $id;
    /**
     * @var integer
     *
     * @ORMColumn(name="status", type="integer", nullable=false)
     */
     private $status;
    /**
     * @ORMColumn(type="string", length=300)
     * @AssertNotBlank(message="Contact Information is required.", groups={"quick"})
     *
     */
     private $contactinfo;
    /** 
     * @ORMColumn(type="datetime")
     * @AssertDateTime(message="Flight Date is not a valid date.", groups={"quick"})
     * @AssertNotBlank(message="Flight Date is required.", groups={"quick"})
     *   */
     private $flightdate;
    /**
     * @ORMColumn(type="string", length=600, nullable=true)
     */
     private $notes;
    /**
     * @ORMManyToOne(targetEntity="Product")
     * @ORMJoinColumn(name="product_id", referencedColumnName="id")
     * @AssertNotNull(message="No Flight selected.")
     **/
     private $flight;
    /**
     * @ORMOneToMany(targetEntity="Passenger", mappedBy="booking", cascade={"all"})
     */
     private $passengers;
     /**
      * @ORMColumn(name="meeting_time", type="time", nullable=true)
      *     
      */
     private $meetingTime;
     /**
     * @ORMManyToOne(targetEntity="MeetingLocation", inversedBy="bookings")
     * @ORMJoinColumn(name="meetinglocation_id", referencedColumnName="id")
     * @AssertNotNull(message="No Meeting Location selected.")
     */
     private $meetingLocation;
    /**
     * @ORMManyToOne(targetEntity="FlightScheduleTime")
     * @ORMJoinColumn(name="flight_schedule_time_id", referencedColumnName="id")
     **/
     private $flightScheduleTime;
     /**
      * @ORMManyToOne(targetEntity="BookingOwner", inversedBy="bookings")
      * @ORMJoinColumn(name="owner_id", referencedColumnName="id")
      */
     private $owner;
    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }
    /**
     * Set status
     *
     * @param integer $status
     * @return CustomerOrder
     */
    public function setStatus($status)
    {
        $this->status = $status;
        return $this;
    }
    /**
     * Get status
     *
     * @return integer 
     */
    public function getStatus()
    {
        return $this->status;
    }
    /**
     * Set contactinfo
     *
     * @param string $contactinfo
     * @return Booking
     */
    public function setContactinfo($contactinfo)
    {
        $this->contactinfo = $contactinfo;
        return $this;
    }
    /**
     * Get contactinfo
     *
     * @return string 
     */
    public function getContactinfo()
    {
        return $this->contactinfo;
    }
    /**
     * Set flightdate
     *
     * @param DateTime $flightdate
     * @return Booking
     */
    public function setFlightdate($flightdate)
    {
        $this->flightdate = $flightdate;
        return $this;
    }
    /**
     * Get flightdate
     *
     * @return DateTime 
     */
    public function getFlightdate()
    {
        return $this->flightdate;
    }
    /**
     * Set notes
     *
     * @param string $notes
     * @return Booking
     */
    public function setNotes($notes)
    {
        $this->notes = $notes;
        return $this;
    }
    /**
     * Get notes
     *
     * @return string 
     */
    public function getNotes()
    {
        return $this->notes;
    }

    /**
     * Add passenger
     *
     * @param AppEntityPassenger $passenger
     * @return Booking
     */
    public function addPassenger(Passenger $passenger)
    {
        if(!$this->passengers->contains($passenger))
        {
            $this->passengers->add($passenger);
        }
        $passenger->addBooking($this);
        // $this->passengers[] = $passenger;
        return $this;
    }
    /**
     * Remove passenger
     *
     * @param AppEntityPassenger $passenger
     */
    public function removePassenger(Passenger $passenger)
    {
        $this->passengers->removeElement($passenger);
    }
    /**
     * Get passengers
     *
     * @return DoctrineCommonCollectionsCollection 
     */
    public function getPassengers()
    {
        return $this->passengers;
    }
    public function getMeetingTime()
    {
        return $this->meetingTime;
    }
    public function setMeetingTime($meetingTime)
    {
        $this->meetingTime = $meetingTime;
        return $this;
    }
    /**
     * Set meetingLocation
     *
     * @param AppEntityMeetingLocation $meetingLocation
     * @return Booking
     */
    public function setMeetingLocation(MeetingLocation $meetingLocation = null)
    {
        $this->meetingLocation = $meetingLocation;
        return $this;
    }
    /**
     * Get meetingLocation
     *
     * @return AppEntityMeetingLocation
     */
    public function getMeetingLocation()
    {
        return $this->meetingLocation;
    }
    /**
     * Set owner
     *
     * @param AppEntityBookingOwner $bookingOwner
     * @return Booking
     */
    public function setOwner(BookingOwner $owner = null)
    {
        $this->owner = $owner;
        return $this;
    }
    /**
     * Get owner
     *
     * @return AppEntityBookingOwner 
     */
    public function getOwner()
    {
        return $this->owner;
    }
/**
     * Set flight
     *
     * @param AppEntityProduct $flight
     * @return Booking
     */
    public function setFlight(Product $flight = null)
    {
        $this->flight = $flight;
        return $this;
    }
    /**
     * Get flight
     *
     * @return AppEntityProduct
     */
    public function getFlight()
    {
        return $this->flight;
    }
        /**
     * Set Flight Schedule Time
     *
     * @param AppEntityFlightScheduleTime $flightScheduleTime
     * @return Booking
     */
    public function setFlightScheduleTime(FlightScheduleTime $flightScheduleTime = null)
    {
        $this->flightScheduleTime = $flightScheduleTime;
        return $this;
    }
    /**
     * Get Flight Time
     *
     * @return AppEntityFlightScheduleTime 
     */
    public function getFlightScheduleTime()
    {
        return $this->flightScheduleTime;
    }
    public function __toString()
    {
        return $this->id."";
    }
}

乘客实体类

<?php
namespace AppEntity;
use DoctrineCommonCollectionsArrayCollection;
use DoctrineORMMapping as ORM;
use GedmoMappingAnnotation as Gedmo;
use SymfonyComponentValidatorConstraints as Assert;
/**
 * @ORMEntity(repositoryClass="AppRepositoryPassengerRepository")
 * @ORMTable(name="passenger")
 */

class Passenger
{
    public function __construct() {
    }
    /**
     * @var integer
     *
     * @ORMColumn(name="id", type="integer")
     * @ORMId
     * @ORMGeneratedValue(strategy="AUTO")
     */
    protected $id;
    /**
     * @ORMColumn(type="string", length=80)
     * @AssertNotBlank(message="Passenger Name is required.", groups={"quick"})
     */
    protected $name;

    /**
     * @ORMManyToOne(targetEntity="Booking", inversedBy="passengers")
     * @ORMJoinColumn(nullable=false, name="booking_id", referencedColumnName="id")
     */
    protected $booking;
    /**
     * @ORMManyToOne(targetEntity="Pilot", inversedBy="passengers")
     * @ORMJoinColumn(name="pilot_id", referencedColumnName="id")
     */
    protected $pilot;
    /**
     * @ORMManyToOne(targetEntity="Product")
     * @ORMJoinColumn(name="product_id", referencedColumnName="id")
     **/
    protected $flight;
    /**
     * @ORMOneToOne(targetEntity="Purchase", inversedBy="passenger", cascade={"all"})
     * @ORMJoinColumn(name="purchase_id", referencedColumnName="id")
     **/
     protected $purchase;
    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }
    /**
     * Set name
     *
     * @param string $name
     * @return Passenger
     */
    public function setName($name)
    {
        $this->name = $name;
        return $this;
    }
    /**
     * Get name
     *
     * @return string 
     */
    public function getName()
    {
        return $this->name;
    }
    /**
     * Add booking
     *
     * @param AppEntityBooking $booking
     * @return Passenger
     */
    public function addBooking(Booking $booking)
    {
        $this->booking = $booking;
        return $this;
    }
    /**
     * Set booking
     *
     * @param AppEntityBooking $booking
     * @return Passenger
     */
    public function setBooking(Booking $booking)
    {
        $this->booking = $booking;
        return $this;
    }
    /**
     * Get booking
     *
     * @return AppEntityBooking
     */
    public function getBooking()
    {
        return $this->booking;
    }
    /**
     * Set pilot
     *
     * @param AppEntityPilot $pilot
     * @return Passenger
     */
    public function setPilot(Pilot $pilot = null)
    {
        $this->pilot = $pilot;
        return $this;
    }
    /**
     * Get pilot
     *
     * @return AppEntityPilot
     */
    public function getPilot()
    {
        return $this->pilot;
    }
    /**
     * Set purchase
     *
     * @param AppEntityPurchase $purchase
     * @return Passenger
     */
    public function setPurchase(Purchase $purchase = null)
    {
        $this->purchase = $purchase;
        return $this;
    }
    /**
     * Get purchase
     *
     * @return AppEntityPurchase
     */
    public function getPurchase()
    {
        return $this->purchase;
    }
    /**
     * Set flight
     *
     * @param AppEntityProduct $flight
     * @return Passenger
     */
    public function setFlight(Product $flight = null)
    {
        $this->flight = $flight;
        return $this;
    }
    /**
     * Get flight
     *
     * @return AppEntityProduct
     */
    public function getFlight()
    {
        return $this->flight;
    }
    public function __toString()
    {
        return $this->name."";
    }
}

作曲家信息

composer info
api-platform/api-pack                    v1.2.0  A pack for API Platform
api-platform/core                        v2.3.6  Build a fully-featured hypermedia or GraphQL API in minutes
behat/transliterator                     v1.2.0  String transliterator
cocur/slugify                            v3.2    Converts a string into a slug.
deployer/recipes                         6.2.1   3rd party deployer recipes
doctrine/annotations                     v1.6.0  Docblock Annotations Parser
doctrine/cache                           v1.8.0  Caching library offering an object-oriented API for many cache backends
doctrine/collections                     v1.5.0  Collections Abstraction library
doctrine/common                          v2.10.0 PHP Doctrine Common project is a library that provides additional functionality that other Doctrin...
doctrine/data-fixtures                   v1.3.1  Data Fixtures for all Doctrine Object Managers
doctrine/dbal                            v2.9.2  Powerful PHP database abstraction layer (DBAL) with many features for database schema introspectio...
doctrine/doctrine-bundle                 1.10.1  Symfony DoctrineBundle
doctrine/doctrine-cache-bundle           1.3.5   Symfony Bundle for Doctrine Cache
doctrine/doctrine-fixtures-bundle        3.1.0   Symfony DoctrineFixturesBundle
doctrine/doctrine-migrations-bundle      v2.0.0  Symfony DoctrineMigrationsBundle
doctrine/event-manager                   v1.0.0  Doctrine Event Manager component
doctrine/inflector                       v1.3.0  Common String Manipulations with regard to casing and singular/plural rules.
doctrine/instantiator                    1.1.0   A small, lightweight utility to instantiate objects in PHP without invoking their constructors
doctrine/lexer                           v1.0.1  Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.
doctrine/migrations                      v2.0.0  PHP Doctrine Migrations project offer additional functionality on top of the database abstraction ...
doctrine/orm                             v2.6.3  Object-Relational-Mapper for PHP
doctrine/persistence                     v1.1.0  The Doctrine Persistence project is a set of shared interfaces and functionality that the differen...
doctrine/reflection                      v1.0.0  Doctrine Reflection component
easycorp/easy-deploy-bundle              v1.0.5  The easiest way to deploy Symfony applications
egulias/email-validator                  2.1.7   A library for validating emails against several RFCs
fzaninotto/faker                         v1.8.0  Faker is a PHP library that generates fake data for you.
gedmo/doctrine-extensions                v2.4.36 Doctrine2 behavioral extensions
jdorn/sql-formatter                      v1.2.17 a PHP SQL highlighting library
knplabs/knp-menu                         2.3.0   An object oriented menu library
knplabs/knp-menu-bundle                  v2.2.1  This bundle provides an integration of the KnpMenu library
monolog/monolog                          1.24.0  Sends your logs to files, sockets, inboxes, databases and various web services
nelmio/cors-bundle                       1.5.4   Adds CORS (Cross-Origin Resource Sharing) headers support in your Symfony2 application
nikic/php-parser                         v4.2.0  A PHP parser written in PHP
ocramius/package-versions                1.3.0   Composer plugin that provides efficient querying for installed package versions (no runtime IO)
ocramius/proxy-manager                   2.1.1   A library providing utilities to generate, instantiate and generally operate with Object Proxies
phpdocumentor/reflection-common          1.0.1   Common reflection classes used by phpdocumentor to reflect the code structure
phpdocumentor/reflection-docblock        4.3.0   With this component, a library can provide support for annotations via DocBlocks or otherwise retr...
phpdocumentor/type-resolver              0.4.0  
psr/cache                                1.0.1   Common interface for caching libraries
psr/container                            1.0.0   Common Container Interface (PHP FIG PSR-11)
psr/log                                  1.1.0   Common interface for logging libraries
psr/simple-cache                         1.0.1   Common interfaces for simple caching
sensio/framework-extra-bundle            v5.2.4  This bundle provides a way to configure your controllers with annotations
sonata-project/admin-bundle              3.45.2  The missing Symfony Admin Generator
sonata-project/block-bundle              3.14.0  Symfony SonataBlockBundle
sonata-project/cache                     2.0.1   Cache library
sonata-project/core-bundle               3.16.1  Symfony SonataCoreBundle
sonata-project/datagrid-bundle           2.4.0   Symfony SonataDatagridBundle
sonata-project/doctrine-extensions       1.1.5   Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 3.8.2   Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/exporter                  1.11.0  Lightweight Exporter library
stof/doctrine-extensions-bundle          v1.3.0  Integration of the gedmo/doctrine-extensions with Symfony2
swiftmailer/swiftmailer                  v6.1.3  Swiftmailer, free feature-rich PHP mailer
symfony/asset                            v4.2.2  Symfony Asset Component
symfony/cache                            v4.2.2  Symfony Cache component with PSR-6, PSR-16, and tags
symfony/config                           v4.2.2  Symfony Config Component
symfony/console                          v4.2.2  Symfony Console Component
symfony/contracts                        v1.0.2  A set of abstractions extracted out of the Symfony components
symfony/debug                            v4.2.2  Symfony Debug Component
symfony/dependency-injection             v4.2.2  Symfony DependencyInjection Component
symfony/doctrine-bridge                  v4.2.2  Symfony Doctrine Bridge
symfony/dotenv                           v4.2.2  Registers environment variables from a .env file
symfony/event-dispatcher                 v4.2.2  Symfony EventDispatcher Component
symfony/expression-language              v4.2.2  Symfony ExpressionLanguage Component
symfony/filesystem                       v4.2.2  Symfony Filesystem Component
symfony/finder                           v4.2.2  Symfony Finder Component
symfony/flex                             v1.1.8  Composer plugin for Symfony
symfony/form                             v4.2.3  Symfony Form Component
symfony/framework-bundle                 v4.2.2  Symfony FrameworkBundle
symfony/http-foundation                  v4.2.2  Symfony HttpFoundation Component
symfony/http-kernel                      v4.2.2  Symfony HttpKernel Component
symfony/inflector                        v4.2.2  Symfony Inflector Component
symfony/intl                             v4.2.3  A PHP replacement layer for the C intl extension that includes additional data from the ICU library.
symfony/maker-bundle                     v1.11.3 Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you ca...
symfony/monolog-bridge                   v4.2.3  Symfony Monolog Bridge
symfony/monolog-bundle                   v3.3.1  Symfony MonologBundle
symfony/options-resolver                 v4.2.3  Symfony OptionsResolver Component
symfony/orm-pack                         v1.0.6  A pack for the Doctrine ORM
symfony/polyfill-intl-icu                v1.10.0 Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-mbstring                v1.10.0 Symfony polyfill for the Mbstring extension
symfony/polyfill-php72                   v1.10.0 Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/process                          v4.2.2  Symfony Process Component
symfony/profiler-pack                    v1.0.4  A pack for the Symfony web profiler
symfony/property-access                  v4.2.2  Symfony PropertyAccess Component
symfony/property-info                    v4.2.2  Symfony Property Info Component
symfony/routing                          v4.2.2  Symfony Routing Component
symfony/security-acl                     v3.0.1  Symfony Security Component - ACL (Access Control List)
symfony/security-bundle                  v4.2.2  Symfony SecurityBundle
symfony/security-core                    v4.2.2  Symfony Security Component - Core Library
symfony/security-csrf                    v4.2.2  Symfony Security Component - CSRF Library
symfony/security-guard                   v4.2.2  Symfony Security Component - Guard
symfony/security-http                    v4.2.2  Symfony Security Component - HTTP Integration
symfony/serializer                       v4.2.2  Symfony Serializer Component
symfony/serializer-pack                  v1.0.2  A pack for the Symfony serializer
symfony/stopwatch                        v4.2.2  Symfony Stopwatch Component
symfony/swiftmailer-bundle               v3.2.5  Symfony SwiftmailerBundle
symfony/templating                       v4.2.3  Symfony Templating Component
symfony/translation                      v4.2.3  Symfony Translation Component
symfony/twig-bridge                      v4.2.2  Symfony Twig Bridge
symfony/twig-bundle                      v4.2.2  Symfony TwigBundle
symfony/validator                        v4.2.2  Symfony Validator Component
symfony/var-dumper                       v4.2.3  Symfony mechanism for exploring and dumping PHP variables
symfony/var-exporter                     v4.2.2  A blend of var_export() + serialize() to turn any serializable data structure to plain PHP code
symfony/web-profiler-bundle              v4.2.3  Symfony WebProfilerBundle
symfony/web-server-bundle                v4.2.2  Symfony WebServerBundle
symfony/yaml                             v4.2.2  Symfony Yaml Component
twig/extensions                          v1.5.4  Common additional features for Twig that do not directly belong in core
twig/twig                                v2.6.2  Twig, the flexible, fast, and secure template language for PHP
webmozart/assert                         1.4.0   Assertions to validate method input/output with nice error messages.
willdurand/negotiation                   v2.3.1  Content Negotiation tools for PHP provided as a standalone library.
zendframework/zend-code                  3.3.1   provides facilities to generate arbitrary code using an object oriented interface
zendframework/zend-eventmanager          3.2.1   Trigger and listen to events within a PHP application

显然我在预订表格和乘客表格的映射方面有一个问题,因此基于此处找到的建议https://rinkovec.com/sonata-one-one-ony-entities-admin-forms/i修改了预订乘客FormField配置以包括自定义表单类型(PassengerType)。

                CollectionType::class,
                    ['allow_add' => true,
                        'by_reference' => false,
                        'allow_delete' => true,
                        'prototype' => true,
                        'entry_type' => PassengerType::class,
                    ]
                )

相关内容

  • 没有找到相关文章

最新更新