简体   繁体   English

symfony2中不同控制器中的同名函数不能在不同的路径下工作

[英]same name function in different controller in symfony2 is not work in different path

this is UserController file 这是UserController文件

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

and this is CmsController file: 这是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');
    }
}

see the difference if i set addAction function not work but i set different name is work properly plz help how to call same name 看到差异,如果我设置addAction功能不起作用,但我设置不同的名称是正常工作PLZ帮助如何调用相同的名称

The internal route names need to be unique, please see symfony: routing : 内部路由名称必须是唯一的,请参阅symfony:routing

The [annotation name] is the internal name of the route, which doesn't have any meaning yet and just needs to be unique. [注释名称]是路径的内部名称,它没有任何意义,只需要是唯一的。 Later, you'll use it to generate URLs. 稍后,您将使用它来生成URL。

This issue is mainly caused due to the same routs. 此问题主要是由于相同的路径引起的。 As we can see your routes are fine please check you have enabled the mod_rewrite module on. 我们可以看到您的路线很好,请检查您是否启用了mod_rewrite模块。 If that does not solve your problem you can generate an issue on there official issue tracker on GitHub on the provided link https://github.com/symfony/symfony/issues/ 如果这不能解决您的问题,您可以在提供的链接上的GitHub上的官方问题跟踪器上生成问题https://github.com/symfony/symfony/issues/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Symfony2-使用相同的控制器,但基于HTTP主机的视图是否不同? - Symfony2 - Use same controller but different view based on HTTP host? Symfony2中同一实体上的不同验证规则 - Different validation rules on same entity in Symfony2 Symfony2使用不同的语言环境刷新同一页面 - Symfony2 refreshing the same page with a different locale 如何使用注解在同一控制器中路由到两个不同的“动作”功能-Symfony2 - How to route to two different 'Action' functions in same controller using annotation - Symfony2 如何从控制器内部访问不同的控制器 Symfony2 - How to access a different controller from inside a controller Symfony2 具有自定义主键名称(不同于“ id”)的symfony2模型 - symfony2 model with custom primary key name (different than “id”) Symfony2和Doctrine:如何为同一个id获取两个不同的对象? - Symfony2 and Doctrine: how to fetch two different object for the same id? 从两个不同的域服务同一个Symfony2应用程序 - Serving the same Symfony2 application from two different domains 如何使用symfony2部署具有不同数据源的相同功能? - How to deploy same functionality, with different data source with symfony2? Symfony2:不同类型的用户 - Symfony2: Different types of users
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM