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 ...
随机推荐
- Spring源代码解析 ---- 循环依赖
一.循环引用: 1. 定义: 循环依赖就是循环引用,就是两个或多个Bean相互之间的持有对方,比方CircularityA引用CircularityB,CircularityB引用Circularit ...
- Java GUI使用exe4j打包exe文件
exe4j下载地址:http://blog.csdn.net/cciii/article/details/17083531 1. 在MyEclipse将java项目打包成可执行jar文件.项目结构如 ...
- Android数字签名解析(三)
在刚才開始学习android数字签名的相关知识点的时候,被资料中出现的keystore.x509.密钥对.debug.keystore弄的晕头 转向.经过一段时间的了解,总算明确一些. 一.make_ ...
- shell语法简单介绍
一.基本的语法 1.1.shell文件开头 shell文件必须以以下的行開始(必须方在文件的第一行): #!/bin/sh 符号#!用来告诉系统它后面的參数是用来运行该文件的程序.在这个样例中我们 ...
- MSSQL、C# 、Winform、ASP.NET - 数据库备份与还原模块
数据库备份还原类: using System; using System.Collections.Generic; using System.Linq; using System.Text; usin ...
- 开发环境FAQ
问: Win7下VS2008无法识别WinCE5.0SDK 答:拷贝WinXP环境(安装过VS2008 + WinCE5.0SDK)下C:/Program Files/Microsoft Visual ...
- Cocos2d-x 手游聊天系统需求分析
手游聊天系统需求分析 转载请注明:IT_xiao小巫 移动开发狂热者群:299402133 策划需求图 參考系统:刀塔传奇 点击这个.然后弹出以下的对话框 游戏类型:卡牌 分析:刀塔传奇聊天系统分为3 ...
- CppCMS URL使用
Artyom觉得URL分为三个组成部分: Script_Name / Path_Info ? Query_String 比方以下的: /foo/bar.php/test?x=10 Script_Nam ...
- Swift - UIView的常用属性和常用方法总结
1,UIView常用的一些属性如下: frame:相对父视图的坐标和大小(x,y,w,h) bounds:相对自身的坐标和大小,所以bounds的x和y永远为0(0,0,w,h) center:相对父 ...
- 【thinking in java】读书笔记(一)
近期開始读tij,好记性不如烂笔头,所以还是记录一下,方便以后查阅. 一.各种初始化问题: 方法重载的问题: 方法的重载,差别是靠传入方法的參数,而不是返回值.比方f(),假设是返回值的话,easy产 ...