新手學習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(” “)中雙引号不可以用單引号;否則會出錯。