FOSCommentBundle功能包:设置Doctrine ODM映射(投票)
短信预约 -IT技能 免费直播动态提醒
原文出处:12b-mapping_mongodb.md
原文作者:FriendsOfSymfony
授权许可:创作共用协议
翻译人员:FireHare
校对人员:
适用版本:FOSCommentBundle 2.0.5
文章状态:草译阶段
Step 12b: Setup MongoDB mapping
The MongoDB implementation does not provide a concrete Vote class for your use,you must create one:
ROM实现并没有提供一个具体的Vote类给您使用,您需要创建一个:
<?php
// class="lazy" data-src/MyProject/MyBundle/Document/Vote.php
namespace MyProject\MyBundle\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
use FOS\CommentBundle\Document\Vote as BaseVote;
class Vote extends BaseVote
{
protected $id;
protected $comment;
}
And you should implement VotableCommentInterface in your Comment class and add a field to your mapping:
并且您需要在您的Comment类中实现 VotableCommentInterface 接口,并添加一个字段到您的映射中:
<?php
// class="lazy" data-src/MyProject/MyBundle/Document/Comment.php
namespace MyProject\MyBundle\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
use FOS\CommentBundle\Document\Comment as BaseComment;
use FOS\CommentBundle\Model\VotableCommentInterface;
class Comment extends BaseComment implements VotableCommentInterface
{
// .. fields
protected $score = 0;
public function setScore($score)
{
$this->score = $score;
}
public function getScore()
{
return $this->score;
}
public function incrementScore($by = 1)
{
$this->score += $by;
}
Configure your application(配置您的应用程序)
In YAML:
YAML格式:
# app/config/config.yml
fos_comment:
db_driver: mongodb
class:
model:
vote: MyProject\MyBundle\Document\Vote
Or if you prefer XML:
如果您偏好XML:
# app/config/config.xml
<fos_comment:config db-driver="mongodb">
<fos_comment:class>
<fos_comment:model
vote="MyProject\MyBundle\Document\Vote"
/>
</fos_comment:class>
</fos_comment:config>
Back to the main step(返回主步骤)
Step 12: Enable voting.
第12步:启用投票。免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341