Home  >  Article  >  Backend Development  >  Laravel 向视图传递变量的3种方法

Laravel 向视图传递变量的3种方法

WBOY
WBOYOriginal
2016-06-23 13:18:501209browse

方法1,

//routs.phpRoute::get('/about',function(){$first = 'hello';return view('about')->with('a',$first);});

接收变量

//about.blade.php{{ $a }}

方法2,

//routs.phpRoute::get('/about',function(){$data = array('a' => 'O','b' => 'K');return view('about',$data);});

接收变量

{{ $a }}{{ $b }}

方法3,

//routs.phpRoute::get('/about',function(){$first = 'hello';$last = 'world';//参数名称要对应return view('about',compact('first','last'));});

接收变量

//about.blade.php{{ $first }}{{ $last }}


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn