将数组传递给laravel中的Redirect :: action [英] Pass an array to Redirect::action in laravel

查看:276
本文介绍了将数组传递给laravel中的Redirect :: action的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将数组从一个函数传递给laravel中的另一个函数.

I'm trying to pass an array from a function to another function in laravel.

在我的PageController.php中,我有

public function show($code, $id){
 //some code
  if(isset($search))
   dd($search);
}

和另一个功能

public function search($code, $id){

//some queries 
$result = DB::table('abd')->get();
return Redirect::action('PageController@show, ['search'=>$search]);
}

但这会给我返回这样的错误:ErrorException (E_UNKNOWN) Array to string conversion

But this returns me an error like this: ErrorException (E_UNKNOWN) Array to string conversion

我正在使用laravel.

I'm using laravel.

推荐答案

您也许可以通过序列化将其与URL传递一起使用,但我宁愿将其存储在会话变量中.会话类具有一个名为flash的不错的方法,该方法将保留下一个请求的变量,然后自动将其删除.

You could maybe get it to work with passing by the URL by serialization, but I'd rather store it in a session variable. The session class has this nice method called flash which will keep the variable for the next request and then automatically remove it.

而且,这只是一个猜测,您可能需要为此使用index动作,因为show需要特定资源的ID.

Also, and that's just a guess, you probably need to use the index action for that, since show needs the id of a specific resource.

public function search($code, $id){
    //some queries 
    $result = DB::table('abd')->get();
    Session::flash('search', $search); // or rather $result?
    return Redirect::action('PageController@index');
}

public function index($code){
    //some code
    if(Session::has('search')){
        $search = Session::get('search');
        dd($search);
    }
}

这篇关于将数组传递给laravel中的Redirect :: action的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆