2015-11-04 23 views
1

我想在->before()中間件中執行檢查並將結果傳遞到路由將內容從之前的中間件傳遞到Silex中的路由器

這可能嗎?該文件似乎沒有提及任何事情。

$app->post('/push/{id}', function($id, Request $request) { 
    // access $foobar here 
}) 
->assert('id', '[a-f\d]{24}') 
->before(function(Request $request){ 
    // do something 
    $foobar = 1; 
}); 

回答

3

沿着數據在全球$應用程序變量傳遞工作

$app['data'] = []; 
$app->post('/push/{id}', function($id, Request $request) use ($app) { 
    // $app['data']['foobar'] = 1; 
}) 
->assert('id', '[a-f\d]{24}') 
->before(function(Request $request) use ($app){ 
    $app['data']['foobar'] = 1; 
}); 
+4

您也可以使用*屬性*將*請求包*對象像這樣:'''$請求 - >屬性 - > set('foo','bar');'''然後在你的控制器關閉只是'''$ request-> attributes-> get('foo')'' – mTorres

+0

@mTorres從來沒有回答,但是,你是顯然是對的:) – Tobias

相關問題