gpt4 book ai didi

php - Laravel 5.0 Session 不能使用静态方法

转载 作者:行者123 更新时间:2023-12-03 02:16:51 26 4
gpt4 key购买 nike

我正在尝试使用 Laravel 5.0 创建应用程序,但在 BaseController 构造函数中使用 Session 方法时遇到问题

这是我的 BaseController 及其构造函数。

use Symfony\Component\HttpFoundation\Session\Session;

class BaseController extends Controller {

/**
* Initializer.
*
* @access public
* @return \BaseController
*/
public function __construct()
{

//set default lang
if (!Session::has('lang')) {
Session::put('lang', App::getLocale());
Cookie::forever('lang', App::getLocale());
} else {
App::setLocale(Session::get('lang'));
}


}
}

但我收到此错误

ContextErrorException in BaseController.php line 22: Runtime Notice: Non-static method Symfony\Component\HttpFoundation\Session\Session::has() should not be called statically, assuming $this from incompatible context

有人知道我做错了什么吗?

最佳答案

而不是:

use Symfony\Component\HttpFoundation\Session\Session;

你应该使用:

use Session;

在此处导入 session 。

关于php - Laravel 5.0 Session 不能使用静态方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27126972/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com