Laravel 4,如何在Route :: controller()上应用过滤器 [英] Laravel 4, how to apply filters on Route::controller()
本文介绍了Laravel 4,如何在Route :: controller()上应用过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道我可以做到
Route::get('foo/bar', array('before' => 'filter', 'uses' => 'Controller@bar'));
应用路由一些过滤器.我也知道Route :: group()方法.无论如何,如果我想以这种方式定义控制器
to apply routes some filter. I am aware of Route::group() method too. Anyway, if i want to define a controller in this way
Route::controller('foo/{id}/bar', 'Controller');
我不能将数组作为第二个参数传递.
i can not pass an array as the 2nd argument.
问题:如何将过滤器应用于以下路线?
Route::controller('foo/{id}/bar', 'Controller');
===编辑
我想在我的route.php中而不是在控制器构造函数中进行编码.
I want to code this in my route.php, not inside a controller constructor.
推荐答案
您可以在控制器的constructor
中使用
In the constructor
of your controller you may use
public function __construct()
{
$this->beforeFilter('auth');
}
还可以使用
Route::group(array('before' => 'auth'), function() {
Route::controller(...);
});
这篇关于Laravel 4,如何在Route :: controller()上应用过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文