我使用SyliusSandbox包开发商店。 Sylius使用xml文件存储实体的ORM模式。
我已将其xml定义复制到我的Bundle并在那里使用。
但对于我自己的实体,我想使用注释。所以,基本上我需要在一个包中混合两种类型的定义。 如果我尝试持久化使用注释的实体,我会收到一个错误,即找不到该实体的xml文件:
找不到名为的映射文件 'ShopBundle \ Resources \ config \ doctrine / ProductLocalized.orm.xml'for class'\ ShopBundle \ Entity \ ProductLocalized'。
我的实体看起来像这样:
<?php
namespace Pixeljets\ShopBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Pixeljets\ShopBundle\Entity\ProductLocalized
*
* @ORM\Table(name="product_localized")
* @ORM\Entity
*/
class ProductLocalized
{
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="Product", inversedBy="localized")
* @ORM\JoinColumn(name="product_id", referencedColumnName="id")
*/
protected $product;
/**
* @var integer $product_id
*
* @ORM\Column(name="product_id", type="integer")
*/
private $product_id;
/**
* @var string $title
*
* @ORM\Column(name="title", type="string", length=255)
*/
private $title;
/**
* @var string $url
*
* @ORM\Column(name="url", type="string", length=255)
*/
private $url;
/**
* @var string $keywords
*
* @ORM\Column(name="keywords", type="string", length=255, nullable=true)
*/
private $keywords;
/**
* @var string $description
*
* @ORM\Column(name="description", type="string", length=255, nullable=true)
*/
private $description;
/**
* @var string $body
*
* @ORM\Column(name="body", type="text", nullable=true)
*/
private $body;
/**
* @var boolean $published
*
* @ORM\Column(name="published", type="boolean")
*/
private $published;
/**
* @var string $lang
*
* @ORM\Column(name="lang", type="string", length=2)
*/
private $lang;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set product_id
*
* @param integer $productId
* @return ProductLocalized
*/
public function setProductId($productId)
{
$this->product_id = $productId;
return $this;
}
/**
* Get product_id
*
* @return integer
*/
public function getProductId()
{
return $this->product_id;
}
/**
* Set title
*
* @param string $title
* @return ProductLocalized
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set url
*
* @param string $url
* @return ProductLocalized
*/
public function setUrl($url)
{
$this->url = $url;
return $this;
}
/**
* Get url
*
* @return string
*/
public function getUrl()
{
return $this->url;
}
/**
* Set keywords
*
* @param string $keywords
* @return ProductLocalized
*/
public function setKeywords($keywords)
{
$this->keywords = $keywords;
return $this;
}
/**
* Get keywords
*
* @return string
*/
public function getKeywords()
{
return $this->keywords;
}
/**
* Set description
*
* @param string $description
* @return ProductLocalized
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set body
*
* @param string $body
* @return ProductLocalized
*/
public function setBody($body)
{
$this->body = $body;
return $this;
}
/**
* Get body
*
* @return string
*/
public function getBody()
{
return $this->body;
}
/**
* Set published
*
* @param boolean $published
* @return ProductLocalized
*/
public function setPublished($published)
{
$this->published = $published;
return $this;
}
/**
* Get published
*
* @return boolean
*/
public function getPublished()
{
return $this->published;
}
/**
* Set lang
*
* @param string $lang
* @return ProductLocalized
*/
public function setLang($lang)
{
$this->lang = $lang;
return $this;
}
/**
* Get lang
*
* @return string
*/
public function getLang()
{
return $this->lang;
}
/**
* Set product
*
* @param Pixeljets\ShopBundle\Entity\Product $product
* @return ProductLocalized
*/
public function setProduct(\Pixeljets\ShopBundle\Entity\Product $product = null)
{
$this->product = $product;
return $this;
}
/**
* Get product
*
* @return Pixeljets\ShopBundle\Entity\Product
*/
public function getProduct()
{
return $this->product;
}
}
?>
我如何告诉'symfony对模式使用注释方法?
答案 0 :(得分:1)
您不能在捆绑包内混合元数据格式:
来自:http://symfony.com/doc/current/book/doctrine.html
A bundle can accept only one metadata definition format. For example, it's not
possible to mix YAML metadata definitions with annotated PHP entity class definitions.
您需要使用两个捆绑包或坚持使用一种格式。
答案 1 :(得分:0)
您应该考虑使用DoctrineExtensions中的可翻译行为来使您的产品支持i18n。应该比为此创建另一个实体容易得多。