search

ThinkPHP第二课 框架MVC目录和URL访问方式

第二课 框架MVC目录和URL访问方式

1.说明:

ThinkPHP是基于MVC的框架,认识框架目录将更好的实现分层,掌握ThinkPHPURL访问就是访问框架的控制器(MVC中的C),共有四种方式,框架中的C起到分模块的作用

url4种访问方式:

1.PATHINFO 模式 -- 重点!!!!!!

http://域名/项目名/入口文件/模块名/方法名/1/1/2/2

2.普通模式

http://域名/项目名/入口文件?m=模块名&a=方法名&1=1&2=2

3.REWRITE模式

http://域名/项目名/模块名/方法名/1/1/2/2

4.兼容模式

http://域名/项目名/入口文件?s=模块名/方法名/1/1/2/2

2.核心内容:

一.ThinkPHP框架对应MVC目录

V(视图层):thinkphp\Home\Tpl

M(模型层):thinkphp\Home\Lib\Model

C(控制器):thinkphp\Home\Lib\Action

二.URL访问方式(4种)

(1)入口文件全名+控制器类前缀名+控制器核心方法名

thinkphp/index.php/Index/indexPATHINFO方式)



(2)普通模式

  

3REWRITE模式

4)兼容模式

三.应用配置


3.工程实例:  

传参访问控制器实例(键值对)


4.文件路径:

5.遇到的问题: 

6.文档:

ThinkPHPconfig.php详细配置文件介绍 

return array(

//模版配置
//------------------------------------------------------------------------------
"TMPL_DETECT_THEME"   =>  false ,   //自动侦测模板主题 
"TMPL_TEMPLATE_SUFFIX"=>'.html',    //默认模板文件后缀
"TMPL_CACHFILE_SUFFIX"=>'.php',     //默认模板缓存后缀
"TMPL_PARSE_STRING"   => '',        //模板引擎要自动替换的字符串,必须是数组形式。例如 array('__MYPATH__'=>Lib_PATH,...) 
"TMPL_ACTION_ERROR"   =>'Public:error',    //错误跳转模板文件 
"TMPL_ACTION_SUCCESS" =>'Public:success', //成功跳转模板文件 
"TMPL_TRACE_FILE"     =>THINK_PATH.'/Tpl/PageTrace.tpl.php',   //页面Trace的模板文件 
"TMPL_EXCEPTION_FILE" =>THINK_PATH.'/Tpl/ThinkException.tpl.php',  //异常页面的模板文件 
"TMPL_ENGINE_TYPE"    => 'Think',    //默认模板引擎 
//以下设置仅对使用Think模板引擎有效 
"TMPL_DENY_FUNC_LIST" =>'echo,exit',  //模板引擎禁用函数 
"TMPL_L_DELIM"        =>'{',    //模板引擎普通标签开始标记 
"TMPL_R_DELIM"        =>'}',    //模板引擎普通标签结束标记 
"TMPL_VAR_IDENTIFY"   =>'array',    //模板变量识别 留空自懂判断 array 数组 obj 对象 
"TMPL_FILE_DEPR"      =>'/',     //模板文件MODULE_NAMEACTION_NAME之间的分割符,只对项目分组部署有效 
"TMPL_STRIP_SPACE"    =>false,    //是否去除模板文件里面癿html空格不换行 
"TMPL_CACHE_ON"       =>true,    //默认开启模板编译缓存 false 的话每次都重新编译模板 
"TMPL_CACHE_TIME"     => -1,     //模板缓存有效期 -1 永久 单位为秒 
"TAGLIB_BEGIN"        =>'标签库标签开始标记 

"TAGLIB_END"          =>'>',     //标签库标签结束标记 
"TAGLIB_BUILD_IN"     =>'cx',    //内置标签库名称 可以添加自己的标签库,多个使用逗号分隔 
"TAGLIB_PRE_LOAD"     =>'',   //预先加载的标签库,无需在每个模板使用 taglib标签加载, 多个使用逗号分隔
"TAG_NESTED_LEVEL"    =>3     //标签嵌套级别

//-------------------------------------------------------------------------
//应用配置
//------------------------------------------------------------------------------
"APP_GROUP_DEPR"      =>'.',  //模块分组之间的分割符
"APP_GROUP_LIST"      =>'',   //项目模块分组列表,多个组之间用逗号分隑,例如 'Admin,Home'
"APP_CONFIG_LIST"     =>array('taglibs','routes','tags','htmls','modules','actions'),  //项目扩展配置文件列表
"APP_DOMAIN_DEPLOY"   =>false,    //是否使用独立域名部署项目,只有在项目目录本身就是网站根目录的情况下开启

//-------------------------------------------------------------------------
//URL配置
//------------------------------------------------------------------------------
"URL_MODEL"           =>1,   //URL模式: 普通模式 1 PATHINFO 2 REWRITE 3 兼容模式 当URL_DISPATCH_ON开启后有效 
                             //默认为PATHINFO 模式,提供最好的用户体验和 SEO支持 
        
"URL_PATHINFO_MODEL"  =>2,   //PATHINFO 模式,默认采用智能模式 
                             //普通模式参数没有顺序/m/module/a/action/id/1 
                             //智能模式制动识别模块和操作/module/action/id/1/ 或者 /module,action,id,1/...
        
"URL_PATHINFO_DEPR"   =>'/', //PATHINFO参数之间分割号 
"URL_ROUTER_ON"       =>true,   //是否开启URL路由 
"URL_HTML_SUFFIX"     =>'.av',   //伪静态后缀设置,例如 .shtml 
"URL_CASE_INSENSITIVE"  =>false, //URL是否不区分大小写,默认区分大小写


//------------------------------------------------------------------------------
//日志配置
//------------------------------------------------------------------------------
"LOG_RECORD"          =>false,  //是否记录网站日志,默认不记录日志 
"LOG_RECORD_LEVEL"    =>array('EMERG','ALERT','CRIT','ERR'),  //允许记录的日志级别
"LOG_FILE_SIZE"       =>2097152,  //日志文件大小限制, 针对文件方式的日志记录,超过会自动生成备份文件


//------------------------------------------------------------------------------
//错误配置
//------------------------------------------------------------------------------
"ERROR_MESSAGE"       =>'您浏览的页面暂时发生了错误!请稍后再试~',   //错误显示信息 非调试模式有效 
"ERROR_PAGE"          =>'',  //错误定向页面,需要填写完整的URL地址


//------------------------------------------------------------------------------
//数据库配置
//------------------------------------------------------------------------------
"DB_CHARSET"          =>'utf8',   //数据库编码,默认采用 utf8 
"DB_DEPLOY_TYPE"      =>0,        //数据库部署方式 :集中式(单一朋务器) 分布式(主从朋务器) 
"DB_RW_SEPARATE"      =>false,    //数据库读写是否分离,分布式数据库方式下面有效 
"DB_FIELDS_CACHE"     =>true,     //开启数据表字段缓存 
"DB_TYPE"             =>'mysql',  //数据库类型 
"DB_HOST"             =>'localhost',  //数据库服务器地址
"DB_NAME"             =>'',       //数据库名称 
"DB_USER"             =>'root',   //数据库用户名 
"DB_PWD"              =>'',       //数据库 密码 
"DB_PORT"             =>3306,     //数据库使用的端口 
"DB_PREFIX"           =>'think_', //数据库癿表前缀 
"DB_SUFFIX"           =>'',       //数据库的表后缀 
"DB_FIELDTYPE_CHECK"  =>false,    //是否迕行字段类型检查


//------------------------------------------------------------------------------
//静态缓存配置
//------------------------------------------------------------------------------
"HTML_FILE_SUFFIX"    =>'.shtml',  //默认静态文件后缀 
"HTML_CACHE_ON"       =>false,     //默认关闭静态缓存 
"HTML_CACHE_TIME"     =>60,        //静态缓存有效期 
"HTML_READ_TYPE"      =>1,         //静态缓存读取方式 0 readfile 1 redirect


//------------------------------------------------------------------------------
//数据缓存配置
//------------------------------------------------------------------------------
"DATA_CACHE_TYPE"     =>'File',     //数据缓存类型 支持 File Db Apc Memcache Shmop Sqlite Xcache Apachenote Eaccelerator 
"DATA_CACHE_PATH"     =>TEMP_PATH   //缓存路径设置 (仅对File方式缓存有效
"DATA_CACHE_TIME"     =>-1,         //数据缓存有效期 
"DATA_CACHE_COMPRESS" =>false,      //数据缓存是否压缩缓存 
"DATA_CACHE_CHECK"    =>false,      //数据缓存是否校验缓存 
"DATA_CACHE_SUBDIR"   =>false,      //使用子目录缓存 (自动根据缓存标识的哈希创建子目录
"DATA_PATH_LEVEL"     =>1,          //子目录缓存级别


//------------------------------------------------------------------------------
//运行时间配置
//------------------------------------------------------------------------------
"SHOW_RUN_TIME"       =>false,      //运行时间显示 
"SHOW_ADV_TIME"       =>false,      //显示详细的运行旪间,SHOW_RUN_TIME开启后有效 
"SHOW_DB_TIMES"       =>false,      //显示数据库读写次数 
"SHOW_CACHE_TIMES"    =>false,      //显示缓存读写次数 
"SHOW_USE_MEM"        =>false,      //显示内存开销 
"SHOW_PAGE_TRACE"     =>false,      //显示页面Trace信息 由 Trace文件定义和Action操作赋值 
"SHOW_ERROR_MSG"      =>true,       //发生错误时显示错误信息


//------------------------------------------------------------------------------
//Cookie设置
//------------------------------------------------------------------------------
"COOKIE_EXPIRE"       =>3600,       //Coodie有效期 
"COOKIE_DOMAIN"       =>'',         //Cookie有效域名 
"COOKIE_PATH"         =>'/',        //Cookie路径 
"COOKIE_PREFIX"       =>'',         //Cookie前缀 避免冲突

 

//-------------------------------------------------------------------------
//令牌验证配置
//------------------------------------------------------------------------------
"TOKEN_ON"            =>true,       //是否开启令牌验证 
"TOKEN_NAME"          =>'__hash__', //令牌验证的表单隐藏字段名称 
"TOKEN_TYPE"          =>'md5',      //令牌验证哈希规则


//------------------------------------------------------------------------------
//默认值配置
//------------------------------------------------------------------------------
"DEFAULT_APP"         =>'@',      //默认模型类所在的项目名称 表示当前项目 
"DEFAULT_GROUP"       =>'Home',   //默认分组 
"DEFAULT_MODULE"      =>'Index',  //默认模块名称 
"DEFAULT_ACTION"      =>'index',  //默认操作名称 
"DEFAULT_THEME"       =>'default',//默认模板主题名称 
"DEFAULT_LANG"        =>'zh-cn',  //默认语言 
"DEFAULT_TIMEZONE"    =>'PRC',    //默认时区 
"DEFAULT_AJAX_RETURN" =>'JSON',   //AJAX 数据返回格式 JSON XML ... 
"DEFAULT_CHARSET"     =>'utf-8',  //默认页面输出编码


//------------------------------------------------------------------------------
//系统变量配置
//------------------------------------------------------------------------------
//下面这些变量配置主要用于URL的特殊传值,在项目中的URL和表单参数尽量不要与之冲突,否则容易造成错误。 
"VAR_PATHINFO"        =>'s',   //PATHINFO 兼容模式获取变量例如 ?s=/module/action/id/1  
"VAR_GROUP"           =>'g',   //默认分组发量 
"VAR_ROUTE"           =>'r',   //默认路由获取变量 
"VAR_MODULE"          =>'m',   //默认模块获取变量 
"VAR_ACTION"          =>'a',   //默认操作获取变量 
"VAR_PAGE"            =>'p',   //默认分页跳转变量 
"VAR_TEMPLATE"        =>'t',   //默认模板切换变量
"VAR_LANGUAGE"        =>'l',   //默认语言切换变量 
"VAR_AJAX_SUBMIT"     =>'ajax',  //默认的AJAX提交变量

 

//-------------------------------------------------------------------------
//语言和时区
//------------------------------------------------------------------------------
"LANG_SWITCH_ON"      => false   //是否开启多语言功能,默认关闭

);
?>

Statement
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
PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

How does PHP handle object cloning (clone keyword) and the __clone magic method?How does PHP handle object cloning (clone keyword) and the __clone magic method?Apr 17, 2025 am 12:24 AM

In PHP, use the clone keyword to create a copy of the object and customize the cloning behavior through the \_\_clone magic method. 1. Use the clone keyword to make a shallow copy, cloning the object's properties but not the object's properties. 2. The \_\_clone method can deeply copy nested objects to avoid shallow copying problems. 3. Pay attention to avoid circular references and performance problems in cloning, and optimize cloning operations to improve efficiency.

PHP vs. Python: Use Cases and ApplicationsPHP vs. Python: Use Cases and ApplicationsApr 17, 2025 am 12:23 AM

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.