【问题标题】:Imported route from a bundle not working in symfony从包中导入的路由在 symfony 中不起作用
【发布时间】:2016-02-29 13:55:24
【问题描述】:

我是 symfony 的新手。

所以我创建了一个名称空间为 Shinobi/UserBundle 的包

在这个包中,我有一个这样的路由配置:

shinobi_user:
    resource: "@ShinobiUserBundle/Controller"
    type:     annotation

在 app/config/routing.yml 我这样写了以下内容:

shinobi_user:
    resource: "@ShinobiUserBundle/Resources/config/routing.yml"
    prefix:   /

app:
    resource: "@AppBundle/Controller/"
    type:     annotation

当我尝试访问此网址时

http://www.pilipinas.local/app_dev.php/default/

它说

没有找到“GET /default/”的路由

这是我在 ShinobiUserBundle 中的控制器:

 /**
 * @Route("/default")
 */
class DefaultController extends Controller
{
    /**
     *  @Route("/", name="user")
     */
    public function indexAction()
    {
        return $this->render('ShinobiUIBundle:Default:index.html.twig');
    }
}

我做错了什么?

谢谢!

【问题讨论】:

    标签: php symfony


    【解决方案1】:

    你不能像那样给整个控制器提供路由。这是错误的。

    删除

    /** * @Route("/default") */

    这部分从控制器中删除

    shinobi_user:
    resource: "@ShinobiUserBundle/Resources/config/routing.yml"
    prefix:   /
    

    这部分来自routing.yml 然后调用

    http://www.pilipinas.local/app_dev.php/

    你会看到你的user 命名的网址,我的意思是这部分;

    /**
     *  @Route("/", name="user")
     */
    public function indexAction()
    {
        return $this->render('ShinobiUIBundle:Default:index.html.twig');
    }
    

    【讨论】:

      猜你喜欢
      • 2018-08-18
      • 1970-01-01
      • 2012-03-10
      • 2019-10-06
      • 2022-08-14
      • 1970-01-01
      • 2012-06-04
      • 1970-01-01
      • 2023-02-02
      相关资源
      最近更新 更多