我创建了一个名为“test”的路由,但symfony找不到它 .
Routing_dev.php
_test:
resource: "@AcmetestBundle/Controller/testController.php"
type: annotation
pattern: /test
将此行添加到AppKernel.php
$bundles[] = new Acme\testBundle\AcmetestBundle();
创建了下面描述的目录
- 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 / test”的路径404未找到 - NotFoundHttpException 1链接异常:ResourceNotFoundException»Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException:在C:\ xampp \中找不到“GET / test”(未捕获的异常)的路由htdocs \ Symfony \ app \ cache \ dev \ classes.php第4560行
1 回答
我想你的意思是写 prefix 而不是模式: