在 imi 框架根目录中执行
composer require topthink/think-template
安装好模板引擎后,找到路径
\vendor\topthink\think-template\src\Template.php
找到 fetch() 渲染模板文件的方法,将最后一行
echo $content;
替换成
return $content;
imi框架中示例代码:
<?php
namespace ImiApp\ApiServer;
use Imi\Controller\HttpController;
use think\Template;
/**
* @Controller("/")
*/
class IndexController extends HttpController
{
/**
* @Action
* @Route("/")
* @View(renderType="html")
* @return void
*/
public function index() {
$config = [
'view_path' => '你需要定义的模板文件路径',
'cache_path' => '你需要定义的模板文件缓存路径',
'view_suffix' => 'html',
];
$template = new Template($config);
return $this->response->write($template->fetch('index', [
'demo' => '赋值到模板中',
]));
}
}imiphp 框架运用实例 www.kangedan.com (之前用的是ThinkPHP6)



