- 在 composer.json里添加"philo/laravel-blade": "3.*"依赖,并且执行composer update
- 在 application/helpers里添加一个 helper, 名为view_helper.php, 内容如下代码片段①。
- 在 config/autoload.php中的$autoload['helper']中添加 view,效果如下:$autoload['helper'] = array('view');
- 复制 application\views\welcome_message.php为application\views\welcome_message.blade.php将里面的{elapsed_time}改为{{$elapsed_time}}
- 在控制器如 application\controllers\Welcome.php中 index 方法更新为如下代码片段②。
- 访问执行此控制器的方法即可看到效果。Enjoy it!
代码片段①
<?php
require_once 'vendor/autoload.php';
use Philo\Blade\Blade;
if (!function_exists('view')) {
    function view($name = NULL, $data = [], $mergeData = []) {
        $CI =& get_instance();
        if (!isset($CI->blade)) {
            $views = __DIR__ . '/../views';
            $cache = __DIR__ . '/../cache';
            $CI->blade = new Blade($views, $cache);
        }
        echo $CI->blade->view()->make($name, $data, $mergeData)->render();
    }
}
代码片段②
public function index()
{
    return view('welcome_message', array('elapsed_time'=>$this->benchmark->elapsed_time('total_execution_time_start', 'total_execution_time_end')));
}