Home > PHP Framework > ThinkPHP > Detailed explanation of separating template files and cache directories in thinkphp

Detailed explanation of separating template files and cache directories in thinkphp

藏色散人
Release: 2021-03-10 08:57:27
forward
2164 people have browsed it

The following tutorial column of thinkphp will introduce to you the method of separating template files and cache directories in thinkphp. I hope it will be helpful to friends in need!

Detailed explanation of separating template files and cache directories in thinkphp

Separate the template file and cache directory in thinkphp

Add two lines of code definition directly to the entry file Path is enough.

<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2014 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
// 应用入口文件
// 检测PHP环境
if(version_compare(PHP_VERSION,'5.3.0','<&#39;))  die(&#39;require PHP > 5.3.0 !');
// 开启调试模式 建议开发阶段开启 部署阶段注释或者设为false
define('APP_DEBUG',True);
// 定义应用目录
define('APP_PATH','./Application/');
// 定义缓存目录
define('RUNTIME_PATH','./Runtime/');
// 定义模板文件默认目录
define("TMPL_PATH","./tpl/");
// 引入ThinkPHP入口文件
require './ThinkPHP/ThinkPHP.php';
// 亲^_^ 后面不需要任何代码了 就是如此简单

框架目录如下:
Copy after login
 thinkphp
    ├─Application 项目逻辑目录
    │  ├─Common 公共模块
    │  │  ├─Common  公共函数目录
    │  │  │  ├─functioin.php 公共函数php文件
    │  │  ├─Conf  公共配置文件目录
    │  │  │  ├─config.php  tp的配置 用于覆盖框架默认配置项
    │  │  │  ├─db.php  数据库配置 用户名 密码等
    │  │  │  ├─webconfig.php  项目的配置;网站名;是否开启网站等
    │  │  ├─Controller  公共控制器目录
    │  │  │  ├─BaseController.class.php 应用最基础的控制器
    │  │  │  ├─HomeBaseController.class.php  Home基础控制器继承BaseController
    │  │  │  ├─AdminBaseController.class.php  Admin基础控制器继承BaseController
    │  │  │  ├─UserBaseController.class.php  User基础控制器继承BaseController
    │  │  │  ├─...
    │  │  ├─Model  公共模型目录
    │  │  │  ├─BaseModel.class.php  应用最基础的Model
    │  │  │  ├─ArticleModel.class.php 文章model  继承BaseModel
    │  │  │  ├─UserModel.class.php  用户model 继承BaseModel
    │  │  │  ├─...
    │  │  ├─Tag  公共标签目录
    │  │  │  ├─My.class.php  自定义的标签库
    │  │  │  ├─...
    │  ├─Home  Home模块
    │  │  ├─Controller  Home控制器目录 继承HomeBaseController
    │  │  │  ├─ArticleController.class.php 文章控制器目录
    │  │  │  ├─IndexController.class.php  首页控制器
    │  │  │  ├─ ...
    │  ├─Admin  Admin模块
    │  │  ├─Controller  Admin控制器目录 继承AdminBaseController
    │  │  │  ├─IndexController.class.php  后台管理首页控制器
    │  │  │  ├─ ...
    │  ├─User  User模块
    │  │  ├─Controller  User控制器目录 继承UserBaseController
    │  │  │  ├─IndexController.class.php  用户个人中心首页控制器
    │  │  │  ├─ ...
    ├─Public 资源文件目录
    │  ├─install      安装引导目录
    │  ├─statics      静态资源目录
    │  │  ├─bootstrap bootstrap框架
    │  │  ├─ueditor   ueditor编辑器
    │  │  ├─js        jquery等第三方js存放的目录
    │  │  ├─css       animate.css等第三方css目录
    │  │  ├─ ...
    ├─tpl 视图文件目录
    │  ├─Public  公共目录
    │  │  ├─js  公共js目录
    │  │  │  ├─base.js 全站都引用的js文件
    │  │  │  ├─ ...
    │  │  ├─css  公共css目录
    │  │  │  ├─base.css 全站都引用的css文件
    │  │  │  ├─ ...
    │  │  ├─images 公共图片目录
    │  │  ├─public_head.html  全站通用的公共头部
    │  │  ├─public_foot.html  全站通用的公共底部
    │  │  ├─...
    │  ├─Home  前台Home视图目录
    │  │  ├─Public 前台Home的公共目录
    │  │  │  ├─js  home下调用的js文件目录
    │  │  │  ├─css  home下调用的css文件目录
    │  │  │  ├─images  home下调用的图片文件目录
    │  │  ├─Index  首页文件目录
    │  │  │  ├─index.html 首页
    │  │  │  ├─ ...
    │  ├─Admin  同Home
    │  ├─User   同Home
    ├─Upload  公共上传目录
    │  ├─images   上传的图片目录
    │  │  ├─avatar  头像目录
    │  │  ├─ueditor ueditor编辑器上传的图片目录
    │  │  │ ...
    │  │ ...
    ├─Runtime 缓存目录
    ├─ThinkPHP 框架系统目录
Copy after login

Then you can define some directories in the /Application/Common/Conf/config.php file

<?php
return array(
    //&#39;配置项&#39;=>'配置值'
    'TMPL_PARSE_STRING'      => array(    // 定义常用路径
        '__PUBLIC__'         => __ROOT__.'/Public',
        '__HOME_CSS__'       => __ROOT__.trim(TMPL_PATH,'.').'Home/Public/css',
        '__HOME_JS__'        => __ROOT__.trim(TMPL_PATH,'.').'Home/Public/js',
        '__HOME_IMAGES__'    => __ROOT__.trim(TMPL_PATH,'.').'Home/Public/images',
        '__ADMIN_CSS__'      => __ROOT__.trim(TMPL_PATH,'.').'Admin/Public/css',
        '__ADMIN_JS__'       => __ROOT__.trim(TMPL_PATH,'.').'Admin/Public/js',
        '__ADMIN_IMAGES__'   => __ROOT__.trim(TMPL_PATH,'.').'Admin/Public/images',
        '__ADMIN_ACEADMIN__' => __ROOT__.trim(TMPL_PATH,'.').'Admin/Public/aceadmin',
        '__PUBLIC_CSS__'     => __ROOT__.trim(TMPL_PATH,'.').'Public/css',
        '__PUBLIC_JS__'      => __ROOT__.trim(TMPL_PATH,'.').'Public/js',
        '__PUBLIC_IMAGES__'  => __ROOT__.trim(TMPL_PATH,'.').'Public/images',
        '__USER_CSS__'       => __ROOT__.trim(TMPL_PATH,'.').'User/Public/css',
        '__USER_JS__'        => __ROOT__.trim(TMPL_PATH,'.').'User/Public/js',
        '__USER_IMAGES__'    => __ROOT__.trim(TMPL_PATH,'.').'User/Public/images',
        '__APP_CSS__'        => __ROOT__.trim(TMPL_PATH,'.').'App/Public/css',
        '__APP_JS__'         => __ROOT__.trim(TMPL_PATH,'.').'App/Public/js',
        '__APP_IMAGES__'     => __ROOT__.trim(TMPL_PATH,'.').'App/Public/images'
    ),
);
然后在html文件中就可以直接使用这些路径了,美滋滋~
Copy after login

Related recommendations:The latest 10 thinkphp videos Tutorial

The above is the detailed content of Detailed explanation of separating template files and cache directories in thinkphp. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template