controller
1.创建controller
`php artisan make:controller controllername`
注:`php artisan make:controller controllername –plain`不携带自定义方法
2.使用controller
Routes: Route::get('/','SitesController@index');
SC:
<code><span>public</span><span><span>function</span><span>index</span><span>()</span> {</span><span>return</span><span>"sjming"</span>; }</code>
3.参数传递
(1)单值:
SC:
<code><span>public</span><span><span>function</span><span>index</span><span>()</span> {</span><span>$name</span> = <span>'sjming'</span>; <span>return</span> view(<span>'welcome'</span>)->with(<span>'name'</span>,<span>$name</span>); }</code>
(2)数组
<code><span>return</span> view<span><span>(<span>'welcome'</span>)</span>-></span><span>with</span>([ <span>'name'</span><span>=></span>$name, <span>'first'</span><span>=></span><span>'su'</span> ]);</code>
(3)作为view的参数
<code><span>$data</span>=[]; <span>$data</span>[<span>'first'</span>]=<span>'123'</span>; <span>$data</span>[<span>'second'</span>]=<span>'456'</span>; <span>return</span> view(<span>'sites.about'</span>,<span>$data</span>);</code>
(4)php的compact
<code><span>$fir</span>=<span>'123'</span>; <span>$sec</span>=<span>'456'</span>; <span>return</span> view(<span>'sites.about'</span>,compact(<span>'fir'</span>,<span>'sec'</span>));</code>
4.参数使用
转义方式:{{}} //其中的html不解释
不转义方式:{!! !!} //其中的html解释
blade模板
以上就介绍了laravel(一)路由,参数传递,blade,包括了laravel,blade方面的内容,希望对PHP教程有兴趣的朋友有所帮助。