我知道symfony建议使用默认的AppBundle(如本页所述http://symfony.com/doc/current/best_practices/creating-the-project.html),但是,因为我的项目由许多独立的应用程序组成,所以我想将它们分成自己的捆绑包。
我正试图在symfony2控制台generate:bundle命令的帮助下生成一个bundle。目录结构似乎都在适当的位置,但是我经常收到一个错误消息,即虽然我已经定义了路由,但它没有定义
我得到的例外:
request.ERROR:未捕获的PHP异常Symfony''Component''HttpKernel''Exception''NotFoundHttpException:在C:''wamp''www''Symfony''test''app''cache''prod''classes.PHP行2480{"Exception":"[object](Symfony''coomponent''WttpKernel''Exception ''NotFoundHttpException(代码:0(:未找到"GET/hello/somename"的路由''"在C:''wamp''www''symfony''test''app''cache''prod''classes.php:2480,symfony''Component''Routing''Exception''ResourceNotFoundException(代码:0(:在C:''wamp ''www''symfony''t''test''app''cache''prod''appProdUrlMatcher.php:35("}[]
设置如下:
routing.yml:
my:
resource: "@MyBundle/Resources/config/routing.php"
prefix: /
app:
resource: "@AppBundle/Controller/"
type: annotation
routing.php:
use Symfony'Component'Routing'RouteCollection;
use Symfony'Component'Routing'Route;
$collection = new RouteCollection();
$collection->add('my_homepage', new Route('/hello/{name}', array(
'_controller' => 'MyBundle:Default:index',
)));
return $collection;
MyBundle/Controller/DefaultController.php
namespace MyBundle'Controller;
use Symfony'Bundle'FrameworkBundle'Controller'Controller;
class DefaultController extends Controller
{
public function indexAction($name)
{
return $this->render('MyBundle:Default:index.html.twig', array('name' => $name));
}
}
捆绑包也在AppKernel类中正确注册。
据我所知,调用mydomain.local/hello/somename应该可以,但它不起作用。
附言:我也尝试了注释方法,但它也不起作用(我得到了相同的结果(
附言2我知道这是一个很难回答的问题,但到目前为止,我找到的答案似乎都没有帮助我解决这个问题
p.S.3默认的AppBundle工作正常,使用类似的设置(但使用注释(
调试消息表明您处于prod环境中。
您是否尝试过从开发环境mydomain.local/app_dev.php/hello/somename访问路由或清除缓存?