Doctrine 2 annotation embeddable не работает в Symfony 2.8 на Windows.ошибка `имя содержит незаконные символы`, в Doctrine 2 встраивается в Symfony 2,8 form
@ORM \ Embeddable не работает, я получаю сообщение об ошибке: Имя "address.addr_line_1" содержит недопустимые символы. Имена должны начинаться с буквы, цифры или подчеркивания и содержать только буквы, цифры, цифры, символы подчеркивания («_»), дефисы («-») и двоеточия («:»). Ошибка исходит от поставщика ... \ 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;
}
}
Одним из решений является поставить разрешение на использование точку в 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);
Это работает, новая форма генерируется, но я не протекал futher еще, потому что мне нужно генерировать специальные методы получения и установки в встраиваемый. Кажется, лучшим решением является использование признака, как описано здесь: http://russellscottwalker.blogspot.co.uk/2013/11/entities-vs-value-objects-and-doctrine-2.html
Тем не менее, если кто-то знает, как заставить встроенный работать, не изменяя код поставщика Symfony, не могли бы вы написать.
Может быть, он будет работать с прямыми запросами, как SELECT, FROM O порядка о WHERE o.address.addr_line_1 =: line1 http://welcometothebundle.com/persist-the-money-doctrine-value-object/ Он не работает с Symfony форме.
ОТМЕТЬТЕ, что вы не знали об этом. Что еще не так с Доктриной? – olga
Из-за того, что вы используете Windows, вы не можете иметь два класса с похожим именем, потому что Windows нечувствительна к строкам со строками. – panche14