Heim  >  Artikel  >  Backend-Entwicklung  >  Laravel 向视图传递变量的3种方法

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

WBOY
WBOYOriginal
2016-06-23 13:18:501173Durchsuche

方法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 }}


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn