忽略了自定义可重用Bundle的Symfony 3路由

时间:2017-11-07 15:46:50

标签: php symfony bundle

我正在为我的项目创建一个可重用的包,这很大程度上取决于覆盖。奇怪的是,在某些时候我的路由被忽略了,我无法让它工作。

Note: AppBundle extends MyBundle

的routing.yml

my:
    resource: '@MyBundle/Controller/'
    type: annotation
app:
    resource: '@AppBundle/Controller/'
    type: annotation

的src / MyBundle /控制器/ IndexController.php

<?php

namespace MyBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

class IndexController extends Controller
{
    /**
     * Index
     *
     * @Route("/", name="index")
     * @Method("GET")
     */
    public function indexAction()
    {
        return $this->render('index.html.twig');
    }

}

composer.json

...
"autoload": {
    "psr-4": {
        "AppBundle\\": "src/AppBundle",
        "MyBundle\\": "src/MyBundle"
    },
    "classmap": [
        "app/AppKernel.php",
        "app/AppCache.php"
    ]
},
...

但我仍然得到 NotFoundHttpException - 找不到“GET /”的路线

我是否错过了捆绑包的一些特殊配置?

更新:显然它与托管捆绑包有关。当我删除getParent()函数时,一切都按预期工作 - 但我需要这个来覆盖包。

namespace AppBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class AppBundle extends Bundle
{
    public function getParent()
    {
        return 'MyBundle';
    }

}

1 个答案:

答案 0 :(得分:3)

试试'../../src/MyBundle/Controller'和'../../ src / AppBundle / Controller'

它是known issue,但是“bundle inheritance is now deprecated and will be removed in Symfony 4”。

相关问题