thinkphp视图输出

1.前台静态首页存放位置

前端文件的视图位于application的模块下面的view文件夹下。

渲染模板最常用的是使用\think\View类的fetch方法:

当前模块/默认视图目录/当前控制器(小写)/当前操作(小写).html

2前台静态资源存放位置

前端的静态资源(css,js,image)存放于puclic/static文件夹下,

前后台文件区分,在static文件夹中新建一个index文件夹。

3.输出替换

模块index下的controller下的index.php文件,

需要在index.php中引入并在Index类进行继承:

[php]  view plain  copy
  1. <?php  
  2. namespace app\index\controller;  
  3. use think\Controller;  
  4. class Index extends Controller  
  5. {  
  6.     public function index()  
  7.     {  
  8.         return $this->fetch();  
  9.     }  
  10. }  

config.php里面找到 // 视图输出字符串内容替换(默认是空的)

  'view_replace_str'       => [],
  • 1

在其中添加如下代码:

    'view_replace_str'       => [
        '__PUBLIC__' => '/static/index ',//意思是__PUBLIC__就代表了/static/index字符串,而服务器默认的地址是配置到了public(public下一级目录就是static)所以变相的__PUBLIC__就代表了从根目录到admin的路径(比如demo中就是:127.5.2.8\thinkphp_5.0.5_full\public\static\admin)
    ],
css现在的引入方式该为:

[html]  view plain  copy
  1. <link rel="stylesheet" type="text/css" href="__PUBLIC__/static/index/css/style.css">  
浏览器输入http://localhost/tp5/public/index.php/index/index

猜你喜欢

转载自blog.csdn.net/clearloveyt/article/details/80238375
今日推荐