简体   繁体   English

在laravel控制器中如何将变量从一个函数传递到另一函数

[英]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.

相关问题 Laravel:如何在同一控制器中将变量从一个函数传递给来自Ajax调用的另一个函数 - Laravel : how to pass variable from one function to other coming from ajax call in same controller 将参数从一个函数传递到同一控制器 Laravel 中的另一个函数 - Pass parameter from one function to other function in the same Controller Laravel Laravel Controller-在函数之间传递变量 - Laravel Controller - Pass a variable from function to function Laravel将变量从控制器中的1个函数传递给另一个函数 - Laravel pass variable from 1 function in controller to another one Laravel - 在控制器中将变量传递给另一个函数 - Laravel - In controller pass variable to one function to another 在laravel控制器中,将变量传递给一个功能给另一个功能 - In laravel in controller pass variable to one function to another function laravel中从一个函数到另一个函数的变量 - variable from one function to other in laravel 如何在PHP中将变量从一个函数传递给另一个函数? - How to pass variable from one function to other in PHP? 如何使用数组变量将值从一个 function 传递到另一个 - How to pass values from one function to the other using an array variable laravel 5.7 如何将一个控制器的变量 id 传递给另一个 - laravel 5.7 how to pass variable id of one controller to other
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM