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 ...
随机推荐
- 一步一步重写 CodeIgniter 框架 (1) —— url 如何映射到具体的方法
CodeIgniter 框架最显著的特征就是 MVC 模式,它的做法就是提取 url 中的'分段', 映射到某个类的某个方法,从而由该方法来输出最终显示的页面内容.那么我们第一课中就是实现一个这样的原 ...
- IntelliJ Idea 经常使用快捷键列表
Alt+回车 导入包,自己主动修正Ctrl+N 查找类Ctrl+Shift+N 查找文件Ctrl+Alt+L 格式化代码 Ctrl+Alt+O 优化导入的类和包Alt+Insert 生成代码(如 ...
- 增强SEO的div+css命名规则
页头:header登录条:loginBar标志:logo侧栏:sideBar广告:banner导航:nav子导航:subNav菜单:menu子菜单:subMenu搜索:search滚动:scroll页 ...
- 关于for循环中i=0与i=arr.length容易被忽视的bug
for循环中的这两种写法 for(var i=0,len=arr.length;i<len;i++){ } 上面这种是最为常见也是初学者经常写的 而下面这种写法,在性能上则是比上面的更好,然而我 ...
- yii Query Builder (yii 查询构造器) 官方指南翻译
/**** Query Builder translated by php攻城师 http://blog.csdn.net/phpgcs Preparing Query Builder 准备 Quer ...
- Appium TestNg Maven Android Eclipse java简单启动实例
环境准备 Eclipse + maven + appium + TestNg 确保已经在Eclipse 上面安装maven TestNg的插件 打开Eclipse,新建一个java项目,把项目转换成m ...
- StackOverFlow的2016统计
http://stackoverflow.com/research/developer-survey-2016
- Delphi XE2 升级项目编译ralease版本,无法添加UAC解决方法
我今天把一个原来是Delphi2007的工程升级到了Delphi XE2,在编译ralease版本时候,发现无法添加UAC,我觉得可能是升级的原因,随后我用XE2新建了一个工程,但是在编译raleas ...
- Scanner类及正则表达式
import java.util.Scanner; public class ScannerToString { public static void main(String[] args) { Sc ...
- autotools入门笔记(一)
GNU autotools作用:收集系统配置信息并自动生成Makefile文件. GNU autotools主要包括三个工具:autoconf.automake.libtool,还有很多辅助的工具,包 ...