コントローラーでフォームを作成するだけです:
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)); ?>