我正在创建一个功能,可以在Sylius中为产品添加评论。
所以我在CommentProduct
src/Sylius/Component/Product/Model/CommentProduct.php
我为CommentProduct
定义了ORM映射:
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping
xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:gedmo="http://gediminasm.org/schemas/orm/doctrine-extensions-mapping"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"
>
<mapped-superclass name="Sylius\Component\Product\Model\CommentProduct" table="sylius_product_comment">
<id name="id" type="integer" column="id">
<generator strategy="AUTO"/>
</id>
<field name="createdAt" type="datetime" column="created_at">
<gedmo:timestampable on="create"/>
</field>
<field name="updatedAt" type="datetime" column="updated_at" nullable="true">
<gedmo:timestampable on="update"/>
</field>
<field name="commentParentId" type="integer" column="comment_parent_id"/>
<field name="commentText" type="string" column="comment_text" length="1000"/>
<field name="userId" type="integer" column="created_by"/>
<many-to-one field="product" target-entity="Sylius\Component\Product\Model\ProductInterface" inversed-by="comments">
<join-column name="product_id" referenced-column-name="id" nullable="false" />
</many-to-one>
</mapped-superclass>
</doctrine-mapping>
在Product.orm.xml
中,我为产品和评论添加了一对多的关系
<one-to-many field="comments" target-entity="Sylius\Component\Product\Model\CommentProduct" mapped-by="product" orphan-removal="true">
<cascade>
<cascade-all/>
</cascade>
</one-to-many>
所以现在我想拥有一个模型ProductComment
的存储库,我看到另一个存储库,调用就像:
$country = $this->get('sylius.repository.country');
但是当我打电话时:
$commentRepo = $this->container->get('sylius.repository.commentproduct');
我有一个例外:
您已请求不存在的服务“sylius.repository.commentproduct”。
所以我必须为我的模型设置存储库?有人可以帮帮我吗?非常感谢你
答案 0 :(得分:0)
您需要在SyliusResourceBundle中注册资源,例如http://docs.sylius.org/en/latest/bundles/SyliusResourceBundle/configuration.html#basic-configuration