2
私はsonata admin generatorを使用してCRUDを実装しようとしています。symfony 2 sonata admin generatorを使ってdoctrine one to manyリレーションに埋め込むフォーム
私は2つのテーブルとベンダーとベンダーの連絡先を持っています。 私のエンティティのテーブルは、この
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity
* @ORM\Table(name="vendor")
*/
class Vendor{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\OneToMany(targetEntity="VendorContact", mappedBy="vendor_contact")
*/
public $contact;
/**
* @ORM\Column(type="string", length=100)
*/
protected $name;
/**
* @ORM\Column(type="string", length=100)
*/
protected $userName;
/**
* @ORM\Column(type="string", length=100)
*/
protected $password;
/**
* @ORM\Column(type="integer")
*/
private $status;
/**
* @ORM\Column(type="date")
*/
protected $contractBeginDate;
/**
* @ORM\Column(type="date")
*/
protected $contractEndDate;
/**
* @ORM\Column(type="datetime", nullable="true")
*/
protected $createdAt;
/**
* @ORM\Column(type="datetime", nullable="true")
*/
protected $updatedAt;
public function __construct()
{
$this->contact = new ArrayCollection();
}
そして、私のベンダーの連絡先エンティティクラスのようなもので、このよう
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity
* @ORM\Table(name="vendor_contact")
*/
class VendorContact{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="Vendor", inversedBy="contact")
* @ORM\JoinColumn(name ="vendor_id", referencedColumnName="id")
*/
protected $vendorContact;
/**
* @ORM\Column(type="string", length=1000)
*/
protected $street;
/**
* @ORM\Column(type="string", length=100)
*/
protected $city;
/**
* @ORM\Column(type="string", length=100)
*/
protected $state;
/**
* @ORM\Column(type="string", length=100)
*/
protected $country;
/**
* @ORM\Column(type="string", length=50)
*/
protected $zip;
/**
* @ORM\Column(type="string", length=50)
*/
protected $contact_numb;
/**
* @ORM\Column(type="string", length=100)
*/
protected $email;
/**
* @ORM\Column(type="integer")
*/
protected $contact_type;
/**
* @ORM\Column(type="datetime", nullable="true")
*/
protected $createdAt;
/**
* @ORM\Column(type="datetime", nullable="true")
*/
protected $updatedAt;
である私のソナタ管理クラスは次のようである:
class VendorAdmin extends Admin
{
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->with('General')
->add('name')
->add('user_name','text')
->add('password','text')
->add('status')
->add('contract_begin_date','date')
->add('contract_end_date','date');
$formMapper->add('contact', 'collection', array('type' => new VendorContactType()));
// ->end();
;
}
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('id')
->add('name')
->add('userName')
->add('contractBeginDate')
->add('contractEndDate')
->add('_action', array(), array(
'actions' => array(
'edit' => array(),
),
))
;
}
}
そして、ベンダーの連絡先ビルダーは次のようなものです:
私はこれを実行しているときにソナタ管理crud機能を使用してベンダー連絡先のフォームフィールドを取得していません。私はラベル連絡先を取得中です。
誰でも助けてください。
ありがとうございます。