Symfony 4 と Sonata Admin 3 を使用しており、予約エンティティの管理者を構築しようとしています。Booking は Passenger と一対多の関係にあります。予約フォームは期待どおりに表示されますが、送信すると次のメッセージが表示されます...
Warning: spl_object_hash() expects parameter 1 to be object, string given
よろしくお願いします。
BookingAdmin クラス
<?php
namespace App\Admin;
use App\Entity\MeetingLocation;
use App\Entity\Passenger;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\Type\CollectionType;
use Sonata\AdminBundle\Form\Type\ModelListType;
use Sonata\AdminBundle\Form\Type\ModelType;
use Sonata\AdminBundle\Show\ShowMapper;
use Sonata\Form\Type\DateTimePickerType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
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')
;
}
}
PassengerAdmin クラス
<?php
namespace App\Admin;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Show\ShowMapper;
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 App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="App\Repository\BookingRepository")
* @ORM\Table(name="booking")
* @Gedmo\SoftDeleteable(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 \Doctrine\Common\Collections\ArrayCollection();
$this->status = self::STATUS_NEW;
}
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var integer
*
* @ORM\Column(name="status", type="integer", nullable=false)
*/
private $status;
/**
* @ORM\Column(type="string", length=300)
* @Assert\NotBlank(message="Contact Information is required.", groups={"quick"})
*
*/
private $contactinfo;
/**
* @ORM\Column(type="datetime")
* @Assert\DateTime(message="Flight Date is not a valid date.", groups={"quick"})
* @Assert\NotBlank(message="Flight Date is required.", groups={"quick"})
* */
private $flightdate;
/**
* @ORM\Column(type="string", length=600, nullable=true)
*/
private $notes;
/**
* @ORM\ManyToOne(targetEntity="Product")
* @ORM\JoinColumn(name="product_id", referencedColumnName="id")
* @Assert\NotNull(message="No Flight selected.")
**/
private $flight;
/**
* @ORM\OneToMany(targetEntity="Passenger", mappedBy="booking", cascade={"all"})
*/
private $passengers;
/**
* @ORM\Column(name="meeting_time", type="time", nullable=true)
*
*/
private $meetingTime;
/**
* @ORM\ManyToOne(targetEntity="MeetingLocation", inversedBy="bookings")
* @ORM\JoinColumn(name="meetinglocation_id", referencedColumnName="id")
* @Assert\NotNull(message="No Meeting Location selected.")
*/
private $meetingLocation;
/**
* @ORM\ManyToOne(targetEntity="FlightScheduleTime")
* @ORM\JoinColumn(name="flight_schedule_time_id", referencedColumnName="id")
**/
private $flightScheduleTime;
/**
* @ORM\ManyToOne(targetEntity="BookingOwner", inversedBy="bookings")
* @ORM\JoinColumn(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 \App\Entity\Passenger $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 \App\Entity\Passenger $passenger
*/
public function removePassenger(Passenger $passenger)
{
$this->passengers->removeElement($passenger);
}
/**
* Get passengers
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getPassengers()
{
return $this->passengers;
}
public function getMeetingTime()
{
return $this->meetingTime;
}
public function setMeetingTime($meetingTime)
{
$this->meetingTime = $meetingTime;
return $this;
}
/**
* Set meetingLocation
*
* @param \App\Entity\MeetingLocation $meetingLocation
* @return Booking
*/
public function setMeetingLocation(MeetingLocation $meetingLocation = null)
{
$this->meetingLocation = $meetingLocation;
return $this;
}
/**
* Get meetingLocation
*
* @return \App\Entity\MeetingLocation
*/
public function getMeetingLocation()
{
return $this->meetingLocation;
}
/**
* Set owner
*
* @param \App\Entity\BookingOwner $bookingOwner
* @return Booking
*/
public function setOwner(BookingOwner $owner = null)
{
$this->owner = $owner;
return $this;
}
/**
* Get owner
*
* @return \App\Entity\BookingOwner
*/
public function getOwner()
{
return $this->owner;
}
/**
* Set flight
*
* @param \App\Entity\Product $flight
* @return Booking
*/
public function setFlight(Product $flight = null)
{
$this->flight = $flight;
return $this;
}
/**
* Get flight
*
* @return \App\Entity\Product
*/
public function getFlight()
{
return $this->flight;
}
/**
* Set Flight Schedule Time
*
* @param \App\Entity\FlightScheduleTime $flightScheduleTime
* @return Booking
*/
public function setFlightScheduleTime(FlightScheduleTime $flightScheduleTime = null)
{
$this->flightScheduleTime = $flightScheduleTime;
return $this;
}
/**
* Get Flight Time
*
* @return \App\Entity\FlightScheduleTime
*/
public function getFlightScheduleTime()
{
return $this->flightScheduleTime;
}
public function __toString()
{
return $this->id."";
}
}
旅客エンティティ クラス
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="App\Repository\PassengerRepository")
* @ORM\Table(name="passenger")
*/
class Passenger
{
public function __construct() {
}
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string", length=80)
* @Assert\NotBlank(message="Passenger Name is required.", groups={"quick"})
*/
protected $name;
/**
* @ORM\ManyToOne(targetEntity="Booking", inversedBy="passengers")
* @ORM\JoinColumn(nullable=false, name="booking_id", referencedColumnName="id")
*/
protected $booking;
/**
* @ORM\ManyToOne(targetEntity="Pilot", inversedBy="passengers")
* @ORM\JoinColumn(name="pilot_id", referencedColumnName="id")
*/
protected $pilot;
/**
* @ORM\ManyToOne(targetEntity="Product")
* @ORM\JoinColumn(name="product_id", referencedColumnName="id")
**/
protected $flight;
/**
* @ORM\OneToOne(targetEntity="Purchase", inversedBy="passenger", cascade={"all"})
* @ORM\JoinColumn(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 \App\Entity\Booking $booking
* @return Passenger
*/
public function addBooking(Booking $booking)
{
$this->booking = $booking;
return $this;
}
/**
* Set booking
*
* @param \App\Entity\Booking $booking
* @return Passenger
*/
public function setBooking(Booking $booking)
{
$this->booking = $booking;
return $this;
}
/**
* Get booking
*
* @return \App\Entity\Booking
*/
public function getBooking()
{
return $this->booking;
}
/**
* Set pilot
*
* @param \App\Entity\Pilot $pilot
* @return Passenger
*/
public function setPilot(Pilot $pilot = null)
{
$this->pilot = $pilot;
return $this;
}
/**
* Get pilot
*
* @return \App\Entity\Pilot
*/
public function getPilot()
{
return $this->pilot;
}
/**
* Set purchase
*
* @param \App\Entity\Purchase $purchase
* @return Passenger
*/
public function setPurchase(Purchase $purchase = null)
{
$this->purchase = $purchase;
return $this;
}
/**
* Get purchase
*
* @return \App\Entity\Purchase
*/
public function getPurchase()
{
return $this->purchase;
}
/**
* Set flight
*
* @param \App\Entity\Product $flight
* @return Passenger
*/
public function setFlight(Product $flight = null)
{
$this->flight = $flight;
return $this;
}
/**
* Get flight
*
* @return \App\Entity\Product
*/
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