【问题标题】:same name function in different controller in symfony2 is not work in different pathsymfony2中不同控制器中的同名函数在不同路径中不起作用
【发布时间】:2015-11-23 06:45:08
【问题描述】:

这是用户控制器文件

class UsersController extends Controller
{
    /**
    * @Route("/users", name="indexAction")
    */
    public function indexAction()
    {
        $em = $this->getDoctrine()->getManager();
        $users = $em->getRepository('AppBundle:Users')->findAll();
        return $this->render('admin/users.htmls.twig', array('users'=>$users));
    }

    /**
    * @Route("/users/add", name="addAction")
    */
    public function addAction()
    {
        return $this->render('admin/addusers.html.twig');
    }
}

这是 CmsController 文件:

class CmsController extends Controller
{
    /**
    * @Route("/cms", name="cmsAction")
    */
    public function cmsAction()
    {
        $em = $this->getDoctrine()->getManager();
        $cms= $em->getRepository('AppBundle:Cms')->findAll();
        return $this->render('admin/mcs.htmls.twig', array('cms'=>$cms));
    }

    /**
    * @Route("/cms/add", name="addAction")
    */
    public function addAction()
    {
        return $this->render('admin/addcms.html.twig');
    }
}

如果我设置 addAction 函数不起作用但我设置不同的名称可以正常工作请查看差异请帮助如何调用相同的名称

【问题讨论】:

  • 请张贴代码而不是图片
  • 不可能 bcos 此代码带有 / 和星号听起来像是注释它未在 stackover 流中设置
  • @Altoyr 请给我解决方案
  • 我不知道,我不是 php 程序员。
  • 如果可能的话,可以帮助分享我的问题

标签: php symfony controller


【解决方案1】:

内部路由名称需要唯一,请看symfony: routing

[注解名称]是路由的内部名称,还没有任何意义,只需要唯一。稍后,您将使用它来生成 URL。

【讨论】:

    【解决方案2】:

    这个问题主要是由于相同的路由引起的。我们可以看到您的路线很好,请检查您是否启用了 mod_rewrite 模块。如果这不能解决您的问题,您可以在 GitHub 上提供的链接上的官方问题跟踪器上生成问题 https://github.com/symfony/symfony/issues/

    【讨论】:

      猜你喜欢
      • 2021-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多