2017-10-19 4 views
1

作成: https://symfony.com/doc/current/create_framework/templating.html を私はルートからanonymus関数の本体は、唯一の助けを借りて、ルートの名前を渡すことで呼び出すことができますどのようにいくつかの論理的な「オーバージャンプ」会いました要求属性の?ルート宣言で見つかったsymfonyの3 /チュートリアルFolowing独自のフレームワークチュートリアル

'_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です。

答えて

1

これで明らかなように、必要な仕事をしてくれます。

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); 
} 

$matcher->match($request->getPathInfo()) 

関連する問題