Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Route::when()不使用Laravel 4_Php_Laravel_Laravel 4 - Fatal编程技术网

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