3

我使用 SyliusSandbox 包开发商店。Sylius 使用 xml 文件来存储实体的 ORM 模式。

我已将其 xml 定义复​​制到我的 Bundle 并在那里使用它。

但对于我自己的实体,我想使用注释。所以,基本上我需要在一个包中混合两种类型的定义。如果我尝试保留一个使用注释的实体,我会收到一个错误,即找不到该实体的 xml 文件:

找不到类“\ShopBundle\Entity\ProductLocalized”的名为“ShopBundle\Resources\config\doctrine/ProductLocalized.orm.xml”的映射文件。

我的实体如下所示:

<?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 对模式使用注释方法?

4

2 回答 2

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.

您将需要使用两个捆绑包或坚持使用一种格式。

于 2012-11-13T21:32:16.647 回答
0

您应该考虑使用DoctrineExtensions中的可翻译行为来使您的产品支持 i18n。应该比为此创建另一个实体容易得多。

于 2012-11-27T14:50:22.783 回答