在 Symfony,前端应用程序中,在另一个模块上使用一个模块的表单

发布于 2024-10-14 04:19:34 字数 280 浏览 1 评论 0原文

我正在使用 Symfony 构建一个项目。它的类似博客的网站。我需要实施: 为每篇文章写评论。每条评论都必须经过编辑等审核。

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

我的问题是我可以使用我的评论模块的 newSuccess 临时值吗?如果是,怎么办?当我复制并粘贴 newSuccess 的内容时,即使有一些配置,它也不起作用。

您知道可以在文章模块中使用评论模块的形式吗?我该如何配置它?

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

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 know 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 (;-

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千笙结 2024-10-21 04:19:34

只需在控制器中创建表单:

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

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)); ?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文