[英]Symfony2 components, loading controllers
I am using routing component to load controllers, and if i use just 我正在使用路由组件加载控制器,如果我只使用
$routes->add(
'index',
new Route('/', array('_controller' => 'indexAction'))
);
my "project" perfectly loads indexAction function, but if i try something like this 我的“项目”完美加载indexAction函数,但是如果我尝试这样的话
$routes->add(
'index',
new Route('/', array('_controller' => 'Test::indexAction'))
);
it says 它说
Uncaught exception 'InvalidArgumentException' with message 'Class "Test" does not exist.'
But i cant find where must be my controllers, or how they must be included to be loaded successfully. 但是我找不到控制器在哪里,或者必须如何包含它们才能成功加载。 If this helps, at this moment i am using composer autoload with PSR-0 standart. 如果有帮助,此刻,我正在使用带有PSR-0标准的作曲家自动加载功能。
就像它在Symfony文档中所说的关于路由一样 ,您必须使用以下模式来命名控制器:
bundle:controller:action
"Full" path solved the problem “全”路径解决了问题
new Route('/', array('_controller' => 'Levelup\\Controller\\Test::indexAction'))
Test::indexAction changed to Levelup\\Controller\\Test::indexAction 测试:: indexAction更改为Levelup \\ Controller \\ Test :: indexAction
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.