我试图使用Laravel框架获取从一个控制器发送到另一个控制器的值,但值为null。任何解决方案?
class MovieController extends Controller
{
public function ViewMovies()
{
$one = 'This is the first variable.';
$two = 'This is the second variable';
return Redirect::action('QualityController@ViewMovies2', ['data1'=>'one', 'data2'=>'two']);
}
}
class QualityController extends Controller
{
public function ViewMovies2(Request $request)
{
$one = Request::get('data1');
$two = Request::get('data2');
echo $one;
echo $two;
}
}
路线:
Route::get('/','MovieController@ViewMovies');
Route::get('/','QualityController@ViewMovies2');
答案 0 :(得分:0)
快速修复
删除第二条路线(Route::get('/','QualityController@ViewMovies2');
)
而不是:
return Redirect::action('QualityController@ViewMovies2', ['data1'=>'one', 'data2'=>'two']);
使用此:
app('App\Http\Controllers\QualityController')->ViewMovies2($one, $two);
你的fucntoion现在应该是:
public function ViewMovies2($one $two)
{
echo $one;
echo $two;
}
编辑:
尝试导入您的控制器:
use App\Http\Controllers\QualityController;
然后像这样调用它:
$result = (new QualityController)->ViewMovies2();
return $result;