Php Route::when()不使用Laravel 4
我有这个基本代码:Php Route::when()不使用Laravel 4,php,laravel,laravel-4,Php,Laravel,Laravel 4,我有这个基本代码: Route::controller('admin', 'AdminController'); Route::when('admin/*', 'admin-auth'); Route::filter('admin-auth',function(){ if(!Auth::user()) return Redirect::to('login'); }); 显然,当我运行应用程序时,Laravel 4 routing无法运行身份验证检查 在我看来,他们改进了Lara
Route::controller('admin', 'AdminController');
Route::when('admin/*', 'admin-auth');
Route::filter('admin-auth',function(){
if(!Auth::user())
return Redirect::to('login');
});
显然,当我运行应用程序时,Laravel 4 routing无法运行身份验证检查
在我看来,他们改进了Laravel 3中用于Laravel 4的“模式”捕捉方式。试着这样称呼你的路线
Route::when('admin/*', ['before' => 'admin-auth', 'uses' => 'adminController@indexAction']);
这将在执行Route::get/post时起作用。不确定何时使用。。仅供参考。试试:
Route::when('admin*', 'admin-auth');
而不是:
Route::when('admin/*', 'admin-auth');
您必须在app/filters.php中编写Route::when()过滤器 只需将Route::when('admin*','auth')移动到app/filters.php,路径admin将需要登录
假设您要查找的是普通登录函数,所以只使用了laravel auth filter。您的过滤器在app/filters.php文件中吗?出现了什么错误?如果您的php版本为5.4,请使用[]作为数组。如果不使用Route::when('admin/*',array('before'=>'admin auth','uses'=>'adminController@indexAction'));