Blogger Information
Blog 3
fans 0
comment 0
visits 3866
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Thinkphp调用模板文件
列彩天要的博客
Original
2245 people have browsed it

直接在控制器输出文本不能满足我的需求,我需要在调用HTML模板文件显示,在本地环境下调用根目录下/template/index里的index.html文件为控制器里index方法的页面。首先,配置config.php文件.

'template'               => [
        'view_path'    => '../template/',  //public文件里的index.php为相对路径起点。
    ],
<?php
namespace app\index\controller;
use \think\Controller;
/*在本地环境下,没有使用↑代码,直接extends \think\Controller,
但是上传到阿里云ecs服务器,显示查找不到controller方法,所以只好使用了use \think\Controller这段代码
然后就没有报错了*/
class Index extends Controller
{
    public function index()
    {
        //因为把模板文件的根目录定义在了根目录下的template文件夹里,所以下面调用的是
        //  /template/index/index.html文件
        return view('/index/index');
    }
}


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!