我正在尝试使用 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'));
}
}
}
但我得到这个错误
BaseController.php 第 22 行中的 ContextErrorException:运行时注意:不应静态调用非静态方法 Symfony\Component\HttpFoundation\Session\Session::has(),假设 $this 来自不兼容的上下文
有谁知道我做错了什么?