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

WBOY
Release: 2016-06-23 13:18:50
Original
1216 people have browsed it

方法1,

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

接收变量

//about.blade.php{{ $a }}
Copy after login

方法2,

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

接收变量

{{ $a }}{{ $b }}
Copy after login

方法3,

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

接收变量

//about.blade.php{{ $first }}{{ $last }}
Copy after login


source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template