這是我的laravel的控制器函數。laravel controller如何將變量從一個函數傳遞給其他函數
public function getDefault()
{
return View::make('layouts.default');
}
public function getURL()
{
$name = Input::all();
$url=$name['url'];
$json_data=file_get_contents($url);
$content=json_decode($json_data,true);
$this->getThemeOne($content);
return View::make('hello');
}
怎樣的$內容的數據傳遞給所有功能:
public function getThemeOne($content)
{
return View::make('themes.home')->with('data',$content);
}
public function getAbout($content)
{
return View::make('themes.about')->with('content',$content);
}
航線代碼:
Route::get('/','[email protected]');//home page
Route::get('/view','[email protected]');
Route::post('/', '[email protected]'); //post url from home page
視圖頁面:
hello.blade.php:
{ link to goto home.blade.php}->
<a href="view">home</a>
home.blade.php:
{{$data['about']}}
請幫助我如何這樣做...
getURL()被調用的地方是什麼? –
問題是否解決?如果仍然出現參數錯誤,請確保您的'json_decode()'返回值是有效的。 – Patrick
從json_decode返回()是有效的...我想告訴你,我有20個控制器中的功能需要$內容數據...有無論如何通過一個函數.. – user3459007