Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel 将变量从一个控制器传递到另一个控制器_Laravel_Laravel 4 - Fatal编程技术网

Laravel 将变量从一个控制器传递到另一个控制器

Laravel 将变量从一个控制器传递到另一个控制器,laravel,laravel-4,Laravel,Laravel 4,我正在尝试将一个变量从一个控制器传递到另一个我尝试使用的控制器 Redirect::to('dashboard/'.$ssid.'/')->with(compact('wname')) 但是不起作用我怎么能做到这一点 这是我的密码 路线 登录控制器 public function post_index() { if(Auth::attempt($credentials)){ $users = User::where('username','=',$email)->

我正在尝试将一个变量从一个控制器传递到另一个我尝试使用的控制器

Redirect::to('dashboard/'.$ssid.'/')->with(compact('wname'))
但是不起作用我怎么能做到这一点

这是我的密码

路线

登录控制器

public function post_index()
  {

  if(Auth::attempt($credentials)){
    $users = User::where('username','=',$email)->get();
      foreach ($users as $value):
        $activated = $value['a_status'];
        $wname = $value['wholename'];

      endforeach;

      if($activated == 1):
          $red= Redirect::to('dashboard/'.$ssid.'/')->with(compact('wholename')); 
      else:
          $red= View::make('login');
      endif;
      return $red;
}

 }
public function showDash($ssid,$wholename)
{
 foreach ($wholename as $userVal):
        $fn = $userVal['firstname'];
        $ln = $userVal['lastname'];
     endforeach;
return View::make('dashboard')->with(compact('fn'));

}
家庭控制器

public function post_index()
  {

  if(Auth::attempt($credentials)){
    $users = User::where('username','=',$email)->get();
      foreach ($users as $value):
        $activated = $value['a_status'];
        $wname = $value['wholename'];

      endforeach;

      if($activated == 1):
          $red= Redirect::to('dashboard/'.$ssid.'/')->with(compact('wholename')); 
      else:
          $red= View::make('login');
      endif;
      return $red;
}

 }
public function showDash($ssid,$wholename)
{
 foreach ($wholename as $userVal):
        $fn = $userVal['firstname'];
        $ln = $userVal['lastname'];
     endforeach;
return View::make('dashboard')->with(compact('fn'));

}

我遇到的错误是,根据laravel的调试器,
缺少HomeController::showDash()的参数2

根据评论更新了答案:

public function post_index()
{

    if(Auth::attempt($credentials)){
    $users = User::where('username','=',$email)->get();
    foreach ($users as $value){
        $activated = $value['a_status'];
        $wname = $value['wholename'];
    }
    if($activated == 1) {
        Redirect::to('dashboard/'.$ssid.'/')->with(['wholename' => $wholename]); 
    }

    return View::make('login');
}


public function showDash($ssid)
{
    $wholename = (Session::has('wholename')) ? Session::get('wholename') : [];
    foreach ($wholename as $userVal) {
        $fn = $userVal['firstname'];
        $ln = $userVal['lastname'];
    }
    return View::make('dashboard')->with(compact('fn'));
}
其他一切都可以保持原样


更新:修复了“全名”中的错误空格(对不起,是自动更正造成的)。

嗯,但是
$wholename
将在地址栏上可见。。我试图隐藏它,这就是为什么我尝试使用
with()
。啊,我明白了。在这种情况下,您需要从会话中提取变量,它不会在方法调用中传递。所以:$wholename=(Session::has(‘全名’)?会话::get('wholename'):[];在foreach的正上方应该这样做,并从方法签名中删除$wholename参数。对不起,我是laravel的新手,如何在laravel中使用会话?使用->with(…)将其添加到会话中。我会更新我上面的答案。我明白了,我所做的实际上是一个会话。。。但是那不起作用。。我做错什么了吗?