我有两个问题:
Q1。我有一个功能:
namespace Core;
class MyRoute {
static function get($slug, $action) {
// code
}
}
我想像laravel router一样定义这个功能:
$checkLogin = function() {
if(Sentry::check()) return false;
return true;
};
MyRoute::get('foo/bar', function() {
//code
})->before($checkLogin);
如何获得$动作和处理?
Q2:我想使用Silex应用程序(路由),我想使用我的静态类,回调到$ app
namespace Core;
class MyRoute {
static function get($slug, $name) {
$app->get('/home/{name}', function ($name) use ($app) {
return 'Home';
});
}
}
多个变量如何使用。
答案 0 :(得分:0)
使用作为参数传递的匿名函数:
function get($slug, $action)
{
$action();
}
带参数的就像这样:
function get($slug, $action)
{
$action( 42 );
}
get( 13 , function($x){echo $x;} );