Windows 上の Symfony 2.8 では、Doctrine 2 アノテーションの埋め込みが機能しません。
@ORM\Embeddable が機能していません。次のエラーが表示されます。名前 "address.addr_line_1" に不正な文字が含まれています。名前は文字、数字、またはアンダースコアで始まり、文字、数字、数字、アンダースコア ("_")、ハイフン ("-")、およびコロン (":") のみを含める必要があります。エラーは vendor...\src\Symfony\Component\Form\FormConfigBuilder.php から発生します。
その理由は、自動生成された名前のドット「address.addr_line_1」にあるようです。
自動プレフィックスを無効にして、独自の名前を付けようとしました。Doctrine は、私が書いた列名を持つテーブルを生成します: addr_line_1。
しかし、生成されたフォームにはドット「address.addr_line_1」のフィールドが含まれていますが、これはエラーThe name xxx contains illegal characters
です。
フォームで使用するaddr_line_1
と、その名前が存在しないというエラーが表示されます。
<?php
namespace Learn\MySQLBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
//use Doctrine\ORM\Mapping\Embeddable;
use Learn\MySQLBundle\Entity\Embeddable\AddressEmb;
use Learn\MySQLBundle\Entity\Embeddable\TelEmb;
/**
* @ORM\Table( name="te12AuthorEmb" )
* @ORM\Entity()
*/
class e12AuthorEmb
{
/**
* @ORM\Id
* @ORM\Column(type="string", length=36)
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class="Learn\MySQLBundle\Doctrine\Generator6")
*/
protected $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string")
*/
protected $name;
// columnPrefix = "address_"
/** @ORM\Embedded( class="Learn\MySQLBundle\Entity\Embeddable\AddressEmb", columnPrefix=false ) */
protected $address;
/** @var string @ORM\Column(type="string", length=200) */
protected $email = '';
// if there is a \Learn.. that cmd does not generate entities and crud, columnPrefix = "tel_"
/** @ORM\Embedded( class="Learn\MySQLBundle\Entity\Embeddable\TelEmb", columnPrefix=false ) */
protected $tel = '';
public function __construct()
{
$this->address = new AddressEmb();
$this->tel = new TelEmb();
}
/**
* Set id
*
* @param string $id
*
* @return e5Author
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* Get id
*
* @return string
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
*
* @return e5Author
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set email
*
* @param string $email
*
* @return e10AuthorEmb
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set address
*
* @param \Learn\MySQLBundle\Entity\Embeddable\AddressEmb $address
*
* @return e10AuthorEmb
*/
public function setAddress(\Learn\MySQLBundle\Entity\Embeddable\AddressEmb $address)
{
$this->address = $address;
return $this;
}
/**
* Get address
*
* @return \Learn\MySQLBundle\Entity\Embeddable\AddressEmb
*/
public function getAddress()
{
return $this->address;
}
/**
* Set tel
*
* @param \Learn\MySQLBundle\Entity\Embeddable\TelEmb $tel
*
* @return e10AuthorEmb
*/
public function setTel(\Learn\MySQLBundle\Entity\Embeddable\TelEmb $tel)
{
$this->tel = $tel;
return $this;
}
/**
* Get tel
*
* @return \Learn\MySQLBundle\Entity\Embeddable\TelEmb
*/
public function getTel()
{
return $this->tel;
}
}
、、
<?php
namespace Learn\MySQLBundle\Entity\Embeddable;
use Doctrine\ORM\Mapping as ORM;
/**
* Description of AddressEmb
*
* @author gintare
*/
/** @ORM\Embeddable */
class AddressEmb
{
/** @ORM\Column( name="addr_line_1", type = "string", nullable=true) */
protected $addr_line_1 = "";
/** @ORM\Column( name="addr_line_2", type = "string", nullable=true) */
protected $addr_line_2 = "";
/** @ORM\Column( name="addr_town", type = "string", nullable=true) */
protected $addr_town = "";
/** @ORM\Column( name="addr_state", type = "string", nullable=true) */
protected $addr_state = "";
/** @ORM\Column( name="addr_postcode", type = "string", nullable=true) */
protected $addr_postcode = "";
/* may be relation to other entity @var \Entities\Country * */
/** @ORM\Column( name="addr_country", type = "string", nullable=true) */
protected $addr_country;
public function __construct( $line_1 = null, $line_2 = null, $town = null,
$state = null, $postcode = null, $country=null )
{
$this->addr_line_1 = $line_1;
$this->addr_line_2 = $line_2;
$this->addr_town = $town;
$this->addr_state = $state;
$this->addr_postcode = $postcode;
$this->addr_country = $country;
}
}
<?php
namespace Learn\MySQLBundle\Entity\Embeddable;
use Doctrine\ORM\Mapping as ORM;
//use Doctrine\ORM\Mapping\Embeddable;
/**
* TelEmb - value object to represent telephone code with country
*
* @author gintare
*/
/** @ORM\Embeddable */
class TelEmb
{
/** @ORM\Column( name="tel_number", type = "string", nullable=true) */
protected $tel_number = "";
/* *@ORM\Column( name="tel_countrycode", type = "string", nullable=true) */
protected $tel_countrycode = "";
/** @ORM\Column( name="tel_country", type = "string", nullable=true) */
protected $tel_country;
/** @ORM\Column( name="tel_type", type = "string", nullable=true) */
protected $tel_type; //mobile, landline,
/** @ORM\Column( name="tel_costinfo", type = "string", nullable=true) */
protected $tel_costinfo; // information about cost
/** @ORM\Column( name="tel_accessinfo", type = "string", nullable=true) */
protected $tel_accessinfo; // information abotu accessability
public function __construct( $number = null, $countrycode = null, $country = null,
$accessinfo = null, $costinfo = null, $type = null )
{
$this->tel_number = $number;
$this->tel_countrycode = $countrycode;
$this->tel_country = $country;
$this->tel_accessinfo = $accessinfo;
$this->tel_costinfo = $costinfo;
$this->tel_type = $type;
}
}
解決策の 1 つは、ドットの使用許可を に入れることC:\Bitnami\wampstack-5.6.20-0\apache2\htdocs\sym\LearnDB\vendor\symfony\symfony\src\Symfony\Component\Form\FormConfigBuilder.php
です。
return '' === $name || null === $name || preg_match('/^[a-zA-Z0-9_][a-zA-Z0-9_\.\-:]*$/D', $name);
これは機能し、新しいフォームが生成されますが、埋め込み可能で特別なゲッターとセッターを生成する必要があるため、まだ先に進みませんでした。最善の解決策は、ここで説明されているように特性を使用することです 。
それにもかかわらず、Symfony ベンダー コードを変更せずに Embedable を機能させる方法を誰かが知っている場合は、書いていただけませんか。
SELECT o FROM Order o WHERE o.address.addr_line_1 = : line1 http://welcometothebundle.com/persist-the-money-doctrine-value-object/のような直接クエリで動作するかもしれ ません。Symfony フォームでは動作しません。