php 在 Laravel 5.2 中找不到类“App\Http\Controllers\Session”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34419378/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Class 'App\Http\Controllers\Session' not found in Laravel 5.2
提问by AiD
Hi guys i'm using sessions in Laravel 5.2 there is my Controller code :
大家好,我在 Laravel 5.2 中使用会话,有我的控制器代码:
if (Session::has('panier'))
{
$panier = Session::get('panier');
}
i try just to get a value from the session , and i got this error :
我只是尝试从会话中获取一个值,但出现此错误:
FatalErrorException in ProduitsController.php line 106: Class 'App\Http\Controllers\Session' not found
How can i resolve it ?
我该如何解决?
回答by Moppo
From the error message:
从错误消息:
Class 'App\Http\Controllers\Session' not found
找不到类“App\Http\Controllers\Session”
I see that Laravel is searching the Session
class in the current namespace: App\Http\Controllers
我看到 Laravel 正在搜索Session
当前命名空间中的类:App\Http\Controllers
The problem is you don't have aliased the class from the global namespace: Session
is a Facade, and all the facades are in the global namespace
问题是你没有从全局命名空间为类取别名:Session
是一个门面,所有的门面都在全局命名空间中
To use the class from the global namespace, put:
要使用全局命名空间中的类,请输入:
use Session;
on top of your controller, after your namespace declaration
在您的控制器之上,在您的命名空间声明之后
Alternatively, you can call the class from the global namespace with:
或者,您可以使用以下命令从全局命名空间调用该类:
\Session::get('panier');