假设我们有一个 Article 模型和一个 Comment 模型。
Article:
columns:
body: text
Comment:
columns:
article_id: integer
message: text
relations:
Article:
local: article_id
foreign: id
foreignAlias: Comments
我们基于“文章”和“评论”路由集合生成 2 个模型:
article:
class: sfDoctrineRouteCollection
options:
module: article
model: Article
comment:
class: sfDoctrineRouteCollection
options:
module: comment
model: Comment
所以,我们基本上每个模型都有 2 个 crud。现在,在文章的显示操作中,我想显示一篇文章,它的相关评论和添加评论的表单。
class articleActions extends sfActions
{
public function executeShow(sfWebRequest $request)
{
$this->article = $this->getRoute()->getObject();
$this->comments = Doctrine::getTable('Comment')->findAllByArticleId ($this->article->getId());
$this->form = new CommentForm();
}
}
问题是如何在文章/显示操作中发布评论时重用评论/新建和评论/创建操作?这是组织代码的正确方法吗?