2014-03-29 28 views
1

我使用的路由組件來加載控制器,如果我只使用Symfony2的組件,裝載控制器

$routes->add(
    'index', 
    new Route('/', array('_controller' => 'indexAction')) 
); 

我的「項目」完全加載的indexAction功能,但如果我嘗試這樣的事情

$routes->add(
    'index', 
    new Route('/', array('_controller' => 'Test::indexAction')) 
); 

它說

Uncaught exception 'InvalidArgumentException' with message 'Class "Test" does not exist.' 

但我不能找到那裏一定是我的控制器,或者他們是如何必須包括d將被成功加載。 如果這有幫助,在這一刻我正在使用作曲家自動加載與PSR-0標準。

+0

是你命名空間的嗎? – DonCallisto

+0

@DonCallisto,看起來像**命名空間Levelup \ Controller; ** – MyMomSaysIamSpecial

回答

0

「全」 路徑解決了這個問題

new Route('/', array('_controller' => 'Levelup\\Controller\\Test::indexAction')) 

測試:: indexAction改爲Levelup \ Controller \ Test :: indexAction

1

就像它在Symfony的DOC約routing說,你必須 名使用此模式控制器:

 bundle:controller:action 
+0

我做到了這一點,不工作:(http://i.imgur.com/4lFxHIa.png – MyMomSaysIamSpecial

+0

什麼是錯誤? –

+0

類「測試」不存在:) – MyMomSaysIamSpecial