<?php /** * Created by PhpStorm * Author:FireRabbit * Date:2021/2/13 * Time:22:06 **/
namespace FireRabbitEngine\Module\View;
use Xiaoler\Blade\Compilers\BladeCompiler; use Xiaoler\Blade\Engines\CompilerEngine; use Xiaoler\Blade\Engines\EngineResolver; use Xiaoler\Blade\Factory; use Xiaoler\Blade\Filesystem; use Xiaoler\Blade\FileViewFinder;
class Blade { protected static $viewPath, $cachePath;
index 继承了 layout/app.blade.php,只需要编写 ‘content’ 部分即可,
这里输出了一个 $name 参数,用来测试模板传参。
调用 blade 模板
编辑 IndexController 的 index 方法:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<?php
namespace App\Controller\Home;
use FireRabbitEngine\Module\Controller\Controller; use FireRabbitEngine\Module\View\Blade;
class IndexController extends Controller { public function index() { $html = Blade::view('index', ['name' => '花花']);
$this->showMessage($html); } }
调用视图的方法为:Blade::view(视图文件名, [参数])
视图文件名即去掉 blade 的名字,如:index.blade.php,即 index。
showMessage 方法即调用 swoole 的 response 输出字符串:
1 2 3 4 5
public function showMessage($message) { $this->httpKernel->getResponse()->header("Content-Type", "text/html; charset=utf-8"); $this->httpKernel->getResponse()->end($message); }