新手学习symfony首先要学会路由Route,而旧版本路由方式是
# app/config/routing.yml
hello:
path: /hello
defaults: { _controller: app.hello_controller:indexAction }
*本文主要讲述annotation方式映射路由
而新版本的路由方式如下
# app/config/routing.yml
hello:
resource: ‘@AppBundle/Controller/ ’
type: annotation
映射Bundle也是一样
如果把新旧方法分不清楚浏览器很可能无法找到正确的路由路径,从而出现route 错误问题。
还有就是在代码里
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
class DemoController
{
/**
* @Route("/hello/{name}", name="_hello", requirements={"name"=".+"})
*/
public function helloAction($name)
{
// ...
}
}
@Route(” “)中双引号不可以用单引号;否则会出错。