如何从laravel

时间:2016-06-04 12:26:16

标签: php laravel

我有两个控制器

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'); 

有人可以帮帮我..

谢谢..

4 个答案:

答案 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)

  1. 你需要将变量$ post_values传递给UserController,如下所示:
  2.   

    返回重定向() - &gt;路线(&#39;用户/签名&#39;,$ post_values);

    1. 你需要在方法getSigning中获取变量,如下所示:
    2.   

      公共函数getSigning($ post_values)

           

      {

           

      的print_r($ post_values);出口;

           

      }