Symfony 2 - 从其他包内的包中执行操作

发布于 2024-12-12 18:21:03 字数 224 浏览 0 评论 0原文

我对这个概念有疑问:我想要捆绑论坛(显示评论、添加新内容等),但我想在另一个捆绑中显示它(比如说 url:/articles/showforum)。我可以在 /articles/showforum 中包含论坛,但链接将是旧的(例如,显示添加新主题的表单:/forum/newtopic)。我想要 /articles/showforum/forum/newtopic 之类的东西 - Symfony 2 中有这样的工具可以实现这一点吗?

I have problem with that concept: I want to have bundle forum (display comments, adding new, etc.), but I want to display it in another bundle (lets say url: /articles/showforum). I can include forum inside /articles/showforum, but links will be the old ones (e.g. to show form to add new topic: /forum/newtopic). I want sth like /articles/showforum/forum/newtopic - is there such a tool in Symfony 2 to achieve this?

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

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

发布评论

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

评论(1

つ低調成傷 2024-12-19 18:21:03

您可以为您的 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(),
    );
}

You can set base routing for your ForumBundle. Here using annotations:

/**
* Forum controller
*
* @Route("/articles/showforum/forum")
*/
class ForumController extends Controller
{...

A base editAction method:

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