symfony 2找不到我创建的路线

时间:2012-02-19 07:19:07

标签: php symfony

我创建了一个名为“test”的路由,但是symfony找不到它。

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
  2. 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 / test”404找不到路由 - NotFoundHttpException 1   链接异常:ResourceNotFoundException»

         

    Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException:无路由   找到“GET / test”(未捕获的例外)at   C:\ xampp \ htdocs \ Symfony \ app \ cache \ dev \ classes.php第4560行

1 个答案:

答案 0 :(得分:2)

我认为您打算写前缀而不是模式:

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