我正在尝试使用 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/