【问题标题】:Filter setup error过滤器设置错误
【发布时间】:2014-06-16 14:44:05
【问题描述】:

我正在关注this 教程并创建了一个非常简单的登录系统,但这里出现错误:

class AdminController extends BaseController {

    public function __construct()
    {
        $this->beforeFilter(function()
        {
            if(Auth::guest()) //check if logged in
                return Redirect::to('admin/login');
        }, ['except' => ['getLogin','postLogin']]);
    }

Symfony\Component\Debug\Exception\FatalErrorException 语法 错误,意外'['

这里:

}, ['except' => ['getLogin','postLogin']]);

【问题讨论】:

  • 然后检查我的答案。方括号初始化器是在 php 5.4 中引入的。

标签: php laravel laravel-4


【解决方案1】:

您可能运行版本PHP < 5.4。 方括号数组初始化([...])在PHP 5.4中引入。

尝试使用array 或更新 PHP。

数组版本

class AdminController extends BaseController {

    public function __construct()
    {
        $this->beforeFilter(
            function(){
                if(Auth::guest()){ //check if logged in
                    return Redirect::to('admin/login');
                }
            },
            array('except' => array('getLogin','postLogin'))
        );
    }

【讨论】:

    【解决方案2】:

    你是否缺少右括号

    class AdminController extends BaseController {
    
    public function __construct()
    {
        $this->beforeFilter(function()
        {
            if(Auth::guest()) //check if logged in
                return Redirect::to('admin/login');
        }, ['except' => ['getLogin','postLogin']]);
    }
    
    } 
    

    【讨论】:

      猜你喜欢
      • 2019-04-29
      • 2016-06-28
      • 1970-01-01
      • 1970-01-01
      • 2013-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多