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
Optimize PHP Code: Reducing Memory Usage & Execution TimeOptimize PHP Code: Reducing Memory Usage & Execution TimeMay 10, 2025 am 12:04 AM

TooptimizePHPcodeforreducedmemoryusageandexecutiontime,followthesesteps:1)Usereferencesinsteadofcopyinglargedatastructurestoreducememoryconsumption.2)LeveragePHP'sbuilt-infunctionslikearray_mapforfasterexecution.3)Implementcachingmechanisms,suchasAPC

PHP Email: Step-by-Step Sending GuidePHP Email: Step-by-Step Sending GuideMay 09, 2025 am 12:14 AM

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

How to Send Email via PHP: Examples & CodeHow to Send Email via PHP: Examples & CodeMay 09, 2025 am 12:13 AM

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

Advanced PHP Email: Custom Headers & FeaturesAdvanced PHP Email: Custom Headers & FeaturesMay 09, 2025 am 12:13 AM

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Guide to Sending Emails with PHP & SMTPGuide to Sending Emails with PHP & SMTPMay 09, 2025 am 12:06 AM

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

What is the best way to send an email using PHP?What is the best way to send an email using PHP?May 08, 2025 am 12:21 AM

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

Best Practices for Dependency Injection in PHPBest Practices for Dependency Injection in PHPMay 08, 2025 am 12:21 AM

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHP performance tuning tips and tricksPHP performance tuning tips and tricksMay 08, 2025 am 12:20 AM

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

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

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.