基础第五讲: Thinkphp控制器

浏览:682 发布日期:2015/04/27 分类:技术分享
什么是控制器

需要为每个模块定义一个控制器类,控制器类的命名规范是:
模块名+Action.class.php (模块名采用驼峰法并且首字母大写)
系统的默认模块是Index,对应的控制器就是项目目录下面的Lib/Action/IndexAction.class.php,类名和文件名一致。默认操作是index,也就是控制器的一个public方法。初次生成项目目录结构的时候,系统已经默认生成了一个默认控制器(就是之前看到的欢迎页面),我们把index方法改成下面的代码:
class IndexAction extends Action {
public function index(){
echo \'hello,world!\';
}
}
控制器必须继承Action类,一个模块可以包括多个操作方法。如果你的操作方法是protected或者private类型的话,是无法直接通过URL访问到该操作的。

URL模式

1.普通模式
http://localhost/index.php?m=index&a=test&var=1&nihao=你好

2.PATHINFO
http://localhost/index.php/index/test/var/1/nihao/你好/

3.REWRITE
http://localhost/index/test/var/1/nihao/你好/

4.兼容模式
http://localhost/index.php?s=/index/test/var/1/nihao/你好/

URL_MODEL = 0 1 2 3


URL路由

\'URL_ROUTER_ON\' => true, //开启路由
\'URL_ROUTE_RULES\' => array( //定义路由规则
\'news/:year/:month/:day\' => array(\'News/archive\', \'status=1\'),
\'news/:id\' => \'News/read\',
\'news/read/:id\' => \'/news/:1\',
),

教程地址: http://www.phpteahouse.com/video/view/38.html
最佳答案
评论( 相关
后面还有条评论,点击查看>>