在你的控制器只需创建形式:
public function executeShowArticle(sfWebRequest $request)
{
// assume weve already retrieved and set $this->article
$comment = new Comment();
$comment->setArticle($this->article);
$this->commentForm = new CommentForm($comment);
}
那么你就可以在模板中为您的文章使用echo $commentForm
如果您正在自定义评论表单的布局,然后将该表单移动到部分内容,然后从文章视图中执行include_partial('comment/form', array('form' => $commentForm);
。或者,您可以制作组件,而不是使用直部分内容...类似于:
// in commentComponents.class.php
public function executeArticleCommentForm()
{
$comment = new Comment();
$comment->setArticle($this->article);
$this->form = new CommentForm($comment);
}
// in article/showArticleSuccess.php
<?php include_component('comment', 'articleCommentForm', array('article' => $article)); ?>
嵌入文章中的评论表单的验证如何?当验证失败时,它是否会重定向到列出所有错误的文章页面?或跳转到评论视图?以及如何成功添加评论后,它会回到文章页面指向评论说您的评论已成功添加? – 2011-02-14 22:05:16