我有两个控制器
Usercontroller
& SeekerController
我在 SeekerController
中有一个功能 public function postCreate()
{
$post_values = $_POST;
return Redirect::to('user/signing')->with('post_values',$post_values);
}
在 UserController 中有一个功能,如
public function getSigning()
{
print_r($post_values);exit;
}
这里我只想尝试从 SeekerController
中的postCreate
函数打印传递的值
但是它显示了像 Undefined variable: post_values
我应该如何检索从postCreate
函数传递的值
我的路线就像这样
Route::controller('/user', 'UserController');
有人可以帮帮我..
谢谢..
答案 0 :(得分:1)
如果您使用的是laravel 5.1,则可以使用更新的功能:https://laravel.com/docs/5.1/responses#redirecting-with-flashed-session-data
SeekerController:
public function postCreate()
{
$post_values = $_POST; //assume you get your data
return redirect()->action('UserController@getSigning')->with('post_values', $post_values);
}
此用户将重定向到新操作后(新请求)
您可以从会话:https://laravel.com/docs/5.1/session#basic-usage
获取数据public function getSigning(Request $request)
{
$post_values= $request->session()->get('post_values');
print_r($post_values);
exit;
}
答案 1 :(得分:1)
您正在将数据刷新到会话,因此使用session()
帮助程序获取数据:
public function getSigning()
{
print_r(session('post_values'));
exit;
}
答案 2 :(得分:0)
谢谢大家的快速回复,
我使用session
完成了这一切,正如你们所说的那样,它对我很有用
<强> SeekerController 强>
public function postCreate()
{
$post_values = $_POST;
\Session::put('post_values', $post_values);
return Redirect::to('user/signing');
}
在 UserController
中public function getSigning()
{
print_r(\Session::get('post_values'));
exit;
}
答案 3 :(得分:0)
返回重定向() - &gt;路线(&#39;用户/签名&#39;,$ post_values);
公共函数getSigning($ post_values)
{
的print_r($ post_values);出口;
}