Model 如何在Sylius中为新模型创建存储库?
我正在创建一个功能,为Sylius中的产品添加注释 所以我在Model 如何在Sylius中为新模型创建存储库?,model,doctrine,repository,entity,sylius,Model,Doctrine,Repository,Entity,Sylius,我正在创建一个功能,为Sylius中的产品添加注释 所以我在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
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>
现在我想为模型ProductComment
创建一个存储库,我看到另一个存储库,它调用如下所示:
$country = $this->get('sylius.repository.country');
但当我打电话时:
$commentRepo = $this->container->get('sylius.repository.commentproduct');
我有一个例外:
您请求了一个不存在的服务“sylius.repository.commentproduct”
所以我必须做些事情来为我的模型建立存储库?有人能帮我吗?非常感谢您需要像这样在SyliusResourceBundle中注册您的资源
$commentRepo = $this->container->get('sylius.repository.commentproduct');