I'm creating a reusable bundle for my projects which depends heavily on overrides. Weirdly at some point my routing got ignored and I can't get it to work.
Note: AppBundle extends MyBundle
routing.yml
my:
resource: '@MyBundle/Controller/'
type: annotation
app:
resource: '@AppBundle/Controller/'
type: annotation
src/MyBundle/Controller/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"
]
},
...
But I still get a NotFoundHttpException - No route found for "GET /"
Am I missing some special configuration for bundles?
Update: obviously it has something to do with parenting the bundle. When I remove the getParent() function everything works as expected again - however I need this to override the bundle.
namespace AppBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class AppBundle extends Bundle
{
public function getParent()
{
return 'MyBundle';
}
}
Try '../../src/MyBundle/Controller' and '../../src/AppBundle/Controller'
It's known issue , but " bundle inheritance is now deprecated and will be removed in Symfony 4 ".
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.