在Silex中将内容从中间件之前传递到路由器
我想在在Silex中将内容从中间件之前传递到路由器,silex,Silex,我想在->before()中间件中执行检查,并将结果传递到路由中 这可能吗?文件似乎没有提到任何东西 $app->post( '/push/{id}', function( $id, Request $request ) { // access $foobar here }) ->assert( 'id', '[a-f\d]{24}' ) ->before(function( Request $request ){ // do something $fo
->before()
中间件中执行检查,并将结果传递到路由中
这可能吗?文件似乎没有提到任何东西
$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;
});
在全局$app变量中传递数据起作用
$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;
});
在全局$app变量中传递数据起作用
$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;
});
您还可以按如下方式使用请求对象的属性包:
$request->attributes->set('foo','bar')代码>然后在你的控制器闭包上只要``$request->attributes->get('foo')``@mTorres没有回答,但是是的,你显然是对的:)你也可以使用请求对象的属性包,如下所示:$request->attributes->set('foo',bar')代码>然后在控制器关闭时,只需``$request->attributes->get('foo')``@mTorres没有回答,但是的,你显然是对的:)