我创建了一个名为“test”的路由,但是symfony找不到它。
Routing_dev.php
_test:
resource: "@AcmetestBundle/Controller/testController.php"
type: annotation
pattern: /test
将此行添加到AppKernel.php
$bundles[] = new Acme\testBundle\AcmetestBundle();
创建了下面描述的目录
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行
答案 0 :(得分:2)
我认为您打算写前缀而不是模式:
_test:
resource: "@AcmetestBundle/Controller/testController.php"
type: annotation
prefix: /test