这是我的laravel的控制器功能。
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');
}
如何将$ content的数据传递给所有函数:
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('/','DataController@getDefault');//home page
Route::get('/view','DataController@getThemeOne');
Route::post('/', 'dataController@getURL'); //post url from home page
查看页面:
hello.blade.php:
{ link to goto home.blade.php}->
<a href="view">home</a>
home.blade.php:
{{$data['about']}}
请帮我怎么做......
答案 0 :(得分:0)
更新
要分享您可以在函数getURL()
中使用的视图中的数据:
View::share('content', $content);
您可以将$content
作为参数传递给您的函数以及您的视图:
public function x {
$name = Input::all();
$url=$name['url'];
$json_data=file_get_contents($url);
$content=json_decode($json_data,true);
$this->getThemeOne( $content ); // or whatever your scope is
}
public function getThemeOne( $content )
{
return View::make('themes.home')->with('content', $content);
}