我对这个概念有疑问:我想要捆绑论坛(显示评论,添加新内容等),但我想在另一个捆绑中显示它(比如url:/ articles / showforum)。我可以在/ articles / showforum中包含论坛,但链接将是旧的(例如,显示表单以添加新主题:/ forum / newtopic)。我想要像/ articles / showforum / forum / newtopic那样 - 在Symfony 2中有这样的工具来实现这个目标吗?
答案 0 :(得分:2)
您可以为ForumBundle设置基本路由。这里使用注释:
/**
* Forum controller
*
* @Route("/articles/showforum/forum")
*/
class ForumController extends Controller
{...
基础editAction方法:
\ForumBundle\ForumController.php
public function editAction($id)
{
$this->editCustom(id);
return array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
}
public function editCustom(id)
{
$em = $this->getDoctrine()->getEntityManager();
$entity = $em->getRepository('ForumBundle:Topic')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Topic entity.');
}
$editForm = $this->createForm(new TopicType(), $entity);
$deleteForm = $this->createDeleteForm($id);
}
\ArticlesBundle\ForumController.php
public function editAction($id)
{
\ForumBundle\Controller\ForumController::editCustom(id);
return array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
}