开发者

in Symfony, Frontend App, Using one of Module's form on another Module

开发者 https://www.devze.com 2023-02-07 05:51 出处:网络
I am building a project with Symfony. Its blog-like web site. I need to implement: Writing comment for every article. Every comment must be moderationed by editors etc.

I am building a project with Symfony. Its blog-like web site. I need to implement: Writing comment for every article. Every comment must be moderationed by editors etc.

Everything is ready. I have a backend, use group, perms. so on. Just i need to comment form on article's show page.

My question is can i use my comment module's newSuccess temp. If yes, how? When i copy and paste the content of newSuccess, its not working evenif some conf.

Do you k开发者_JS百科now there is way to use comment module's form at article module? and how can i configure it?

Thanks for spend your time to read -maybe to answer (;-


Just create the form in your controller:

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);

}

then you can use echo $commentForm in the template for your article. If you are customizing the layout of the comment form then move that form to a partial and do include_partial('comment/form', array('form' => $commentForm); from your article view. alternatively you could make a componet instead of using a straight partial... something like:

// 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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号