2016-11-17 67 views
0

Doctrine 2注解嵌入在Windows上的Symfony 2.8中不起作用。错误`该名称包含非法字符`,可嵌入Symfony中的Doctrine 2中2,8格式

@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; 
    } 
} 

One解决方案,是摆在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呢,因为我需要生成的嵌入特殊的getter和setter。似乎最好的解决方案是使用这里描述的特征:http://russellscottwalker.blogspot.co.uk/2013/11/entities-vs-value-objects-and-doctrine-2.html

尽管如此,如果有人知道如何使嵌入式工作,而无需更改Symfony供应商代码,您可以请写。

也许这将直接查询工作就像 选择o从订单O,其中o.address.addr_line_1 =:一号线 http://welcometothebundle.com/persist-the-money-doctrine-value-object/ 它不与Symfony的形式工作。

回答

1

新版本的Doctrine不允许特殊字符,如下划线。你没有尝试过吗?

写你的变量,类和文件夹Camel Case也被认为是一个很好的做法。

+0

谢谢你不知道这个。教义还有什么不对? – olga

+0

由于您使用的是Windows,所以不能让两个类具有相似的名称,因为Windows对字符串不区分大小写。 – panche14