Symfony的3 /创建自己的框架教程
问题描述:
如下因素教程的请求属性?Symfony的3 /创建自己的框架教程
'_controller'=> function ($request) {
的路线声明发现:
$routes->add('hello', new Routing\Route('/hello/{name}', array(
'name' => 'World',
'_controller'=> function ($request) {
return render_template($request);
}
)));
和
$response = call_user_func($request->attributes->get('_controller'),
在前端控制器发现:
try {
$request->attributes->add($matcher->match($request->getPathInfo()));
$response = call_user_func($request->attributes->get('_controller'),
$request);
} catch (Routing\Exception\ResourceNotFoundException $e) {
$response = new Response('Not Found', 404);
} catch (Exception $e) {
$response = new Response('An error occurred', 500);
}
会有人愿意来解释如何做到的工作?
Thx提前。
答
好吧,现在很清楚,这是匹配者完成必要的工作。
$matcher->match($request->getPathInfo())
在
try {
$request->attributes->add($matcher->match($request->getPathInfo()));
$response = call_user_func($request->attributes->get('_controller'),
$request);
} catch (Routing\Exception\ResourceNotFoundException $e) {
$response = new Response('Not Found', 404);
} catch (Exception $e) {
$response = new Response('An error occurred', 500);
}