2011-01-26 42 views
2

我正在用Symfony构建一个项目。它的博客网站。我需要实施: 为每篇文章写评论。每个评论必须由编辑等主持。在Symfony中,前端应用程序,在另一个模块上使用模块的一种形式

一切都准备好了。我有一个后端,使用组,烫发。等等。只是我需要在文章的展示页面上发表评论。

我的问题是我可以使用我的评论模块的newSuccess温度。如果是,如何?当我复制并粘贴newSuccess的内容时,即使有一些conf,它也不能正常工作。

您是否知道在文章模块中使用注释模块的方式?我如何配置它?

感谢您花时间阅读 - 也许回答(; -

+0

嵌入文章中的评论表单的验证如何?当验证失败时,它是否会重定向到列出所有错误的文章页面?或跳转到评论视图?以及如何成功添加评论后,它会回到文章页面指向评论说您的评论已成功添加? – 2011-02-14 22:05:16

回答

2

在你的控制器只需创建形式:

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)); ?> 
+0

感谢您的回答。它帮助我了解部分和组件 – 2011-01-27 17:34:32

相关问题