合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
# 视图 # 视图 在 控制器目录下 创建TestController.php 文件 ``` <pre class="calibre13">``` <span class="token"><</span><span class="token">?</span>php namespace App\Http\Controllers<span class="token1">;</span> use Illuminate\Http\Request<span class="token1">;</span> <span class="token2">class</span> <span class="token3">TestController</span> <span class="token2">extends</span> <span class="token3">Controller</span> <span class="token1">{</span> <span class="token2">public</span> <span class="token2">function</span> <span class="token3">abc</span><span class="token1">(</span><span class="token1">)</span><span class="token1">{</span> <span class="token2">return</span> <span class="token3">view</span><span class="token1">(</span><span class="token4">'test-info'</span><span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span> <span class="token1">}</span> ``` ``` 在路由web.php中 增加路由 ``` <pre class="calibre13">``` <span class="token"><</span><span class="token">?</span>php use Illuminate\Support\Facades\Route<span class="token1">;</span> use App\Http\Controllers\TestController<span class="token1">;</span> Route<span class="token1">:</span><span class="token1">:</span><span class="token2">get</span><span class="token1">(</span><span class="token4">'/'</span><span class="token1">,</span> <span class="token2">function</span> <span class="token1">(</span><span class="token1">)</span> <span class="token1">{</span> <span class="token2">return</span> <span class="token3">view</span><span class="token1">(</span><span class="token4">'welcome'</span><span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span><span class="token1">)</span><span class="token1">;</span> Route<span class="token1">:</span><span class="token1">:</span><span class="token2">get</span><span class="token1">(</span><span class="token4">'info'</span><span class="token1">,</span> <span class="token1">[</span>TestController<span class="token1">:</span><span class="token1">:</span><span class="token2">class</span><span class="token1">,</span><span class="token4">'abc'</span><span class="token1">]</span><span class="token1">)</span><span class="token1">;</span> ``` ``` 在视图文件夹下创建文件 test-info.php ``` <pre class="calibre13">``` test<span class="token">-</span>info php ``` ``` 访问http://la.com/info 即可输出视图文件 # 视图方法2 创建视图文件 ingo.blade.php 文件内容 ``` <pre class="calibre13">``` info blade php ``` ``` 控制中 直接写 ``` <pre class="calibre13">``` <span class="token"><</span><span class="token">?</span>php namespace App\Http\Controllers<span class="token1">;</span> use Illuminate\Http\Request<span class="token1">;</span> <span class="token2">class</span> <span class="token3">TestController</span> <span class="token2">extends</span> <span class="token3">Controller</span> <span class="token1">{</span> <span class="token2">public</span> <span class="token2">function</span> <span class="token3">abc</span><span class="token1">(</span><span class="token1">)</span><span class="token1">{</span> <span class="token2">return</span> <span class="token3">view</span><span class="token1">(</span><span class="token4">'info'</span><span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span> <span class="token1">}</span> ``` ``` 输出 info blade php # 参数传参 ``` <pre class="calibre13">``` <span class="token2">public</span> <span class="token2">function</span> <span class="token3">abc</span><span class="token1">(</span><span class="token1">)</span><span class="token1">{</span> <span class="token2">return</span> <span class="token3">view</span><span class="token1">(</span><span class="token4">'info'</span><span class="token1">,</span><span class="token1">[</span> <span class="token4">'name'</span><span class="token">=></span><span class="token4">'测试账号'</span><span class="token1">,</span> <span class="token4">'age'</span> <span class="token">=></span> <span class="token5">28</span> <span class="token1">]</span><span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span> ``` ``` 模板接收: ``` <pre class="calibre13">``` info blade php <span class="token1">{</span><span class="token1">{</span>$name<span class="token1">}</span><span class="token1">}</span><span class="token">--</span><span class="token1">{</span><span class="token1">{</span>$age<span class="token1">}</span><span class="token1">}</span> ``` ``` 输出页面: info blade php 测试账号--28