版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zch3210/article/details/84339757
目录文件
controller/Index.php
fetch方法默认访问application/index/view/index/index.html
<?php
namespace app\index\controller;
use think\Controller;
class Index extends Controller
{
public function index()
{
return $this->fetch();
}
}
view/index/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>index</title>
</head>
<body>
<h1>index下的index.html</h1>
</body>
</html>
运行结果如图
controller/article
fetch方法访问application/index/view/article/index.html
扫描二维码关注公众号,回复:
4277643 查看本文章
<?php
namespace app\index\controller;
use think\Controller;
class Article extends Controller
{
public function index()
{
return $this->fetch('article/index');
}
}
article/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>article</title>
</head>
<body>
<h1>article下的index.html</h1>
</body>
</html>
运行结果如图
配置文件引入样式
在index.php入口文件中
在index下添加配置文件config.php
<?php
return [
'view_replace_str' => [
'__PUBLIC__'=>SITE_URL.'/public/static/style/index',
]
];
此时__PUBLIC__的值设置为一个URL:http://localhost/php/Project/tp5/public/static/style/index
在对应路径下添加a.css文件
.mystyle{
font-size: 30px;
color: #953b39;
}
改变index/index.html中内容,引入css样式
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>index</title>
<link type="text/css" rel="stylesheet" href="__PUBLIC__/a.css">
</head>
<body>
__PUBLIC__<br>
<p class="mystyle">index下的index.html</p>
</body>
</html>
此时再次访问则字体大小与颜色改变