2012-02-19 29 views
0

我創建了名爲「test」的路線,但symfony無法找到它。symfony 2找不到我創建的路線

Routing_dev.php

_test: 
    resource: "@AcmetestBundle/Controller/testController.php" 
    type:  annotation 
    pattern: /test 

添加這一行AppKernel.php

$bundles[] = new Acme\testBundle\AcmetestBundle(); 

創建後述的目錄

  1. Acme公司| 1.1 testBundle | 1.11 AcmetestBundle.php | 1.12控制器 | 1.13 testController.php

AcmetestBundle.php

namespace Acme\testBundle; 
use Symfony\Component\HttpKernel\Bundle\Bundle; 
class AcmetestBundle extends Bundle 
{ 
    public function __construct(){ 
     var_dump("initializing ".__DIR__); 
    } 
} 

testController.php

namespace Acme\testBundle\Controller; 
use Symfony\Bundle\FrameworkBundle\Controller\Controller; 
use Symfony\Component\HttpFoundation\RedirectResponse; 
use Acme\DemoBundle\Form\ContactType; 
// these import the "@Route" and "@Template" annotations 
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; 
class testController extends Controller 
{ 
    /** 
    * @Route("/", name="_demo") 
    * @Template() 
    */ 
    public function indexAction() 
    {  var_dump(11); 
     return array(""); 
    } 
} 

瀏覽器記錄:

沒有找到與 「GET /測試」 404未航線找到 - NotFoundHttpException 1鏈接例外:重新sourceNotFoundException»

Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException:在C:\ xampp \ htdocs \ Symfony \ app \ cache \ dev \ classes.php行中找到「GET/test」(未捕獲的異常)線路4560行

+0

是什麼'PHP應用程序/控制檯路線:dump'說? – meze 2012-02-19 09:16:08

回答

2

我想你的意思是寫前綴,而不是模式:

_test: 
    resource: "@AcmetestBundle/Controller/testController.php" 
    type:  annotation 
    prefix: /test 
+0

好的,謝謝它的工作,但模式有什麼問題?我谷歌,但不明白差異 – 2012-02-19 11:57:00

+1

'資源'說你想從外部資源導入模式。 'prefix'只是導入模式的前綴。 – meze 2012-02-19 12:03:04