3.1.2 MVC模式和URL访问
本节课大纲:
一、什么是MVC //了解
M -Model 编写model类 对数据进行操作 使用Model类 来操作数据
V -View 编写html文件,页面呈现
C -Controller 编写类文件(UserAction.class.php) 二、ThinkPHP的MVC特点 //了解
三、ThinkPHP的MVC对应的目录 //了解
M 项目目录/应用目录/Lib/Model C:\wamp\www\thinkphp\Home\Lib\Model V 项目目录/应用目录/Tpl C:\wamp\www\thinkphp\Home\Tpl C 项目目录/应用目录/Lib/Action C:\wamp\www\thinkphp\Home\Lib\Action 命名: xxAction.class.php http://localhost:8080/thinkphp/index.php/Index/index 访问Index模块下的index 方法 四、url访问C //了解 五、url的4种访问方式 //重点!
1.PATHINFO 模式 -- 重点!!!!!!
http://域名/项目名/入口文件/模块名/方法名/键1/值1/键2/值2 http://localhost/thinkphp/index.php/Index/show 2.普通模式
http://域名/项目名/入口文件?m=模块名&a=方法名&键1=值1&键2=值2 3.REWRITE模式
http://域名/项目名/模块名/方法名/键1/值1/键2/值2 4.兼容模式
http://域名/项目名/入口文件?s=模块名/方法名/键1/值1/键2/值2 http://localhost/thinkphp/ 访问的是index.php 主入口文件 http://localhost/thinkphp/index.php/Index/index 模块/方法 C:\wamp\www\thinkphp\Home\Lib\Action 默认模块IndexAction.class.php 比如要创建用户模块 UserAction.class.php class IndexAction extends Action 继承Action类 <?php
// 本类由系统自动生成,仅供测试用途
class IndexAction extends Action {
public function index(){
$this->show('hello-world');
}
} http://localhost/thinkphp/index.php/Index/show 访问Index 模块的show方法 <?php
// 本类由系统自动生成,仅供测试用途
class IndexAction extends Action {
public function index(){
$this->show('hello-world');
}
public function show(){
echo 访问了Index模块的show方法;
}
} 接口传参: <?php
// 本类由系统自动生成,仅供测试用途
class IndexAction extends Action {
public function index(){
$this->show('hello-world');
}
public function show(){ echo 访问了Index模块的show方法;
echo "欢迎你".$_GET['name']";
}
} http://localhost/thinkphp/index.php/Index/show?name=jj http://localhost/thinkphp/index.php/Index/show/name/jj http://localhost/thinkphp/index.php/Index/show/name/xxyyzz 传递多个参数:
<?php
// 本类由系统自动生成,仅供测试用途
class IndexAction extends Action {
public function index(){
$this->show('hello-world');
}
public function show(){ echo 访问了Index模块的show方法;
echo "欢迎你".$_GET['name'].'你的年龄是'.$_GET['age'];
}
} http://localhost/thinkphp/index.php/Index/show/name/xxyyzz/age/22 <?php
// 本类由系统自动生成,仅供测试用途
class IndexAction extends Action {
public function index(){
$this->show('Hello world');
} public function test(){
$this->show('访问Index模块下的show方法');
}
} 访问Index模块下的test方法 get传参: <?php
// 本类由系统自动生成,仅供测试用途
class IndexAction extends Action {
public function index(){
$this->show('Hello world');
} public function test(){
$this->show("欢迎你.$_GET[name]");
}
} http://localhost:8080/thinkphp/index.php/Index/test/name/xxx http://localhost:8080/thinkphp/index.php/Index/test?name=yyy <?php
// 本类由系统自动生成,仅供测试用途
class IndexAction extends Action {
public function index(){
$this->show('Hello world');
} public function test(){
$this->show("欢迎你.$_GET[name].'你的年龄是'.$_GET[age]");
}
} http://localhost:8080/thinkphp/index.php/Index/test?name=yyy&age=3321 http://localhost:8080/thinkphp/index.php/Index/test/name/yyy/age/31313444 //开启调试模式,关闭缓存 define('APP_DEBUG',true); REWRITE模式
开启REWRITE,
3.1.2 MVC模式和URL访问的更多相关文章
- MVC模式和URL访问
一.什么是MVC //了解 M -Model 编写model类 对数据进行操作 使用Model类 来操作数据 V -View 编写html文件,页面呈现 C -Controller 编写类文件(Use ...
- ThinkPHP 3 MVC模式和URL访问
一.什么是MVC //了解 M -Model 编写model类 对数据进行操作 V -View 编写html文件,页面呈现 C -Controlle ...
- phpcms V9 MVC模式 与 URL访问解析
[1]URL访问解析 观察访问网页时的网址,可以得出模块访问方法,如下示例: http://www.abcd.com.cn/phpcms/index.php?m=content&c=index ...
- phpcms(1)phpcms V9 MVC模式 与 URL访问解析(转)
[1]URL访问解析 观察访问网页时的网址,可以得出模块访问方法,如下示例: http://www.abcd.com.cn/phpcms/index.php?m=content&c=index ...
- [ThinkPHP]MVC模块和URL访问
## ThinkPHP 3 MVC模式和URL访问#讲师:赵桐正微博:http://weibo.com/zhaotongzheng 本节课大纲: 一.什么是MVC // ...
- 2016/5/6 thinkphp ①框架 ② 框架项目部署 ③MVC模式 ④控制器访问及路由解析 ⑤开发和生产模式 ⑥控制器和对应方法创建 ⑦视图模板文件创建 ⑧url地址大小写设置 ⑨空操作空控制器 ⑩项目分组
真实项目开发步骤: 多人同时开发项目,协作开发项目.分工合理.效率有提高(代码风格不一样.分工不好) 测试阶段 上线运行 对项目进行维护.修改.升级(单个人维护项目,十分困难,代码风格不一样) 项目稳 ...
- ASP.Net MVC开发基础学习笔记:一、走向MVC模式
一.ASP.Net的两种开发模式 1.1 ASP.Net WebForm的开发模式 (1)处理流程 在传统的WebForm模式下,我们请求一个例如http://www.aspnetmvc.com/bl ...
- [ASP.NET MVC 小牛之路]01 - 理解MVC模式
本人博客已转移至:http://www.exblr.com/liam PS:MVC出来很久了,工作上一直没机会用.出于兴趣,工作之余我将展开对MVC的深入学习,通过博文来记录所学所得,并希望能得到各 ...
- ASP.Net MVC开发基础学习笔记(1):走向MVC模式
一.ASP.Net的两种开发模式 1.1 ASP.Net WebForm的开发模式 (1)处理流程 在传统的WebForm模式下,我们请求一个例如http://www.aspnetmvc.com/bl ...
随机推荐
- hdu 1166 敌兵布阵(线段树,树状数组)
http://acm.hdu.edu.cn/showproblem.php?pid=1166 直接线段树模板 AC代码: #include<iostream> #include<cs ...
- 算法练习之DP 求LCM (最长公共子序列)
1. 对于序列x[1,i]和y[1,j],推导递推公式1.a 假设当前元素同样,那么就将当前最大同样数+12.b 假设当前元素不同.那么就把当前最大同样数"传递"下去 因此递推公式 ...
- Swift - 网络请求报App Transport Security has blocked a cleartext错
使用Xcode7编写iOS9应用时,如果获取http://数据时会报如下错误: App Transport Security has blocked a cleartext HTTP (http:// ...
- NYOJ10,skiing
skiing 时间限制:3000 ms | 内存限制:65535 KB 难度:5 描写叙述 Michael喜欢滑雪百这并不奇怪, 由于滑雪的确非常刺激.但是为了获得速度,滑的区域必须向下倾斜,并且 ...
- Android 点亮屏幕
前言 欢迎大家我分享和推荐好用的代码段~~ 声明 欢迎转载,但请保留文章原始出处: CSDN:http://www.csdn.net ...
- 【SICP感应】3
级数据和符号数据
在本书的第二章学习时,有一个问题我一直很困扰,那是2.2.4举例节.因为没有华丽的输出模式书,它只能有一个对的英文字母.两三个月的这浅浅的学校前Common Lisp同样是真实的,当.了非常赞的线条, ...
- Qt 中文乱码解决大全
源地址:http://blog.csdn.net/xcy2011sky/article/details/7168376 解决中文乱码,最好知道乱码是什么格式比如说:utf-8. 解决方案: 1.让整个 ...
- Delphi中拖动无边框窗口的5种方法
1.MouseMove事件中加入: // ReleaseCapture;// Perform(WM_SYSCOMMAND, $F017 , 0); 2.MouseDown事件中加入: // POSTM ...
- 可执行程序的入口点在那里?(强化概念:程序真正的入口是mainCRTstartup)
今天终于有时间来研究一下一个很大很大的工程编译成一个exe和若干dll后,程序是如果执行它的第一条指令的?操作系统以什么规则来找到应该执行的第一条指令(或说如何找到第一个入口函数的)? 我们以前写wi ...
- CSDN头版头条 《近匠》 Wijmo 5 CTO:从Web到移动,我的25年编程生涯
现年52岁的Bernardo Castilho先生是GrapeCity(中文名为葡萄城)ComponentOne公司的CTO,在与他的对话过程中.充满风趣严谨和厚重的历史感. 当作为年轻人的我们崇拜着 ...