🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## 视图前言 ``` // 安装thinkphp模板引擎 composer require topthink/think-template ``` 详见:[topthink/think-template](https://packagist.org/packages/topthink/think-template) ## 创建core/view/Thinkphp.php ``` <?php namespace core\view; // tp的模板引擎 use think\Template; class Thinkphp implements ViewInterface { protected $template; public function init() { $config = \App::getContainer()->get('config')->get('view'); $this->template = new Template([ 'view_path' => $config['view_path'], 'cache_path' => $config['cache_path'] ]); } public function render($path,array $params = []) { $this->template->assign($params); $path = str_replace('.','/',$path); // .替换成/ return $this->template->fetch($path); } } ``` ## 更改契约 ![](https://img.kancloud.cn/be/d8/bed8493f2e431837362d6ce0e01d7602_884x306.png) 此时已经完成了, 可以正常使用tp模板引擎。 ## 运行 ### 创建views/thinkphp/index.html ``` <h1>{$str}</h1> ``` ### 运行 ![](https://img.kancloud.cn/2b/32/2b3237bf3716329b1253ff01bad4d91b_787x556.png) ![](https://img.kancloud.cn/a0/f1/a0f138b7fd385c37ce1afb64b92ec6dd_715x337.png)