ThinkPhp学习02

时间:2023-03-09 06:27:53
ThinkPhp学习02

原文:ThinkPhp学习02

一、什么是MVC               
 M -Model 编写model类 对数据进行操作
 V -View  编写html文件,页面呈现
 C -Controller 编写类文件(UserAction.class.php)
二、ThinkPHP的MVC特点        
三、ThinkPHP的MVC对应的目录   
 M 项目目录/应用目录/Lib/Model
 V 项目目录/应用目录/Tpl
 C 项目目录/应用目录/Lib/Action
四、url访问C                 
五、url的4种访问方式          
  1.PATHINFO 模式 -- 重点!!!!!!
  http://域名/项目名/入口文件/模块名/方法名/键1/值1/键2/值2

如:http://localhost/thinkphp/test/index.php/Index/show

PATHINFO模式下面,URL是可定制的,例如,通过修改config.php下面的配置:

<?php
return array(
//'配置项'=>'配置值'
'URL_PATHINFO_DEPR'=>'-', // 更改PATHINFO参数分隔符.默认是/
//'URL_CASE_INSENSITIVE' =>true, //开启不区分大小写 );
?>

2.普通模式
  http://域名/项目名/入口文件?m=模块名&a=方法名&键1=值1&键2=值2

如:http://localhost/thinkphp/test/index.php?m=Index&a=show
  3.REWRITE模式
  http://域名/项目名/模块名/方法名/键1/值1/键2/值2

(1)需要apache支持,打开httpd.conf

开启rewrite功能,并重启apache

 #LoadModule rewrite_module modules/mod_rewrite.so  //去掉#号

(2)将.htaccess放置到项目文件夹下

 <IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>

ok,然后就可以http://localhost/thinkphp/test/Index/show 直接访问了,而不需要添加index.php
  4.兼容模式
  http://域名/项目名/入口文件?s=模块名/方法名/键1/值1/键2/值2

如:http://localhost/thinkphp/test/Index.php/?s=Index/show

在调整初期会遇到缓存问题可以通过删除Runtime文件夹,或者开启debug模式

//开启调试模式,默认是关闭
define('APP_DEBUG',true);

注意开启debug模式后 要注意url上大小写规范,否则会报错,也可以在config.php设置

'URL_CASE_INSENSITIVE' =>true,  //开启不区分大小写