[英]in laravel controller how to pass variable from one function to other function
this is my laravel's controller function. 这是我的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');
}
how to pass data of $content to all function: 如何将$ 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 code: 路线代码:
Route::get('/','DataController@getDefault');//home page
Route::get('/view','DataController@getThemeOne');
Route::post('/', 'dataController@getURL'); //post url from home page
view pages: 查看页面:
hello.blade.php:
{ link to goto home.blade.php}->
<a href="view">home</a>
home.blade.php:
{{$data['about']}}
please help me how to do this... 请帮我怎么做...
Update: 更新:
To share data accross views you can use in your function getURL()
: 要在视图之间共享数据,可以在函数getURL()
:
View::share('content', $content);
You can pass $content
as a parameter to your function and to your view like this: 您可以像这样将$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);
}
See the docs http://laravel.com/docs/responses#views 参见文档http://laravel.com/docs/responses#views
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.