Php Laravel从会话中取出和放入不工作
在SimpleController中,我想将简单变量放入会话并获取。在这个我的代码中,在返回到视图并回调到其他函数之后,我的会话为空并返回nullPhp Laravel从会话中取出和放入不工作,php,laravel,laravel-5,Php,Laravel,Laravel 5,在SimpleController中,我想将简单变量放入会话并获取。在这个我的代码中,在返回到视图并回调到其他函数之后,我的会话为空并返回null public function doAction() { $this->order_id = Session::get('order_id'); $this->reference_id = Session::get('reference_id'); dd(Session::get('order_id') . '
public function doAction()
{
$this->order_id = Session::get('order_id');
$this->reference_id = Session::get('reference_id');
dd(Session::get('order_id') . ' ' . Session::get('reference_id'));
}
public function action(Request $request)
{
Session::put('order_id', $request->input('order_id'));
Session::put('reference_id', $request->input('reference_id'));
}
我的路线:
$app->get('paymentRequest', 'PaymentTransactionController@action');
$app->get('doAction', 'PaymentTransactionController@doAction');
我的看法是:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
{{ $request['order_id'] }}
<a href="{{ url('doAction') }}">CLICK</a>
</body>
</html>
文件
{{$request['order_id']}
假设您的代码没有任何问题,可能是配置问题。您使用哪个本地服务器分别托管Vagrant、WAMP、MAMP、Homestead或Nginx?我们可能需要检查的文件很少,比如php.ini和Laravel的config/session.php,或者nginx中的一些配置。请尝试使用\session::save()手动保存它,或者首先尝试使用\session::start()我不知道您为什么在路由文件中使用$app
。但是$app
是Laravel
应用程序的实例,而不是路由的实例
我看不到任何地方写有您可以/可能使用路由文件中的$app
访问url
s的内容
请将您的routes文件更新为以下内容,并应按预期工作:
Route::get('paymentRequest', 'PaymentTransactionController@action');
Route::get('doAction', 'PaymentTransactionController@doAction');
您运行什么样的URL来实现这一点?你使用的是什么版本的Laravel?@MarcinNabiałek他使用第一个url激活激活会话的操作方法,第二个url激活会话。@mahdipishguy我个人建议不要使用Session::put()
和Session::get()
如果你使用L5.1+只是好奇:为什么你使用$app->get(…)
而不是Route::get(…)