一、視圖引入靜態文件
<!--項目的域名是配置到 public,static也是我們放靜態文件的目錄。這裏 /就表示了我們的域名。這樣就能引入 static/index/css/base.css文件 -->
<link rel="stylesheet" href="/static/index/css/base.css" />
<!--
但是上面這種引入方式的移植性不好,如果換了位置方靜態文件需要修改所有的靜態文件路徑。
我們就可以修改 application/config.php 的 view_replace_str
-->
//視圖輸出字符串內容替換
'view_replace_str' => [
__STATIC__=>'/static',
],
<!--
然後用如下方式引入:
-->
<link rel="stylesheet" href="__STATIC__/index/css/base.css" />
二、輸出視圖文件
<?php
namespace app\index\controller;
use think\Controller;
class Index extends Controller
{
public function index()
{
//會自動找到 application/index/view/index.html 文件並輸入。沒有參數默認就是 方法名。
return $this->fetch('index');
}
}