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 ...
随机推荐
- Deamon Thread 讲解
The daemon thread's life cycle is same with the life cycle of the application which starts this daem ...
- Codeforces Round #270 A~D
Codeforces Round #270 A. Design Tutorial: Learn from Math time limit per test 1 second memory limit ...
- OCP-1Z0-051-题目解析-第8题
8. View the Exhibit and examine the structure of the CUSTOMERS table. Which two tasks would require ...
- mysql 初识之日志文件篇
日志文件 1. err日志 error log 记录mysql在运行的过程中所有较为严重的警告和错误信息,以及mysql server每次启动和关闭的详细信息.系统在默认情况下关闭error ...
- PHP - 子类使用父类的构造函数
/* * 子类使用父类中的构造方法. */ //父类方法 class Person { //父类中的构造方法 function __construct(){ echo '这是父类中的构造方法!'; } ...
- Eclipse用法和技巧二十二:快速调整字体大小
团队代码review的时候,一般都会一堆人围着显示器,或者投影仪.这个时候调整代码字体大小就显得很重要.下面直接说操作方式. 步骤一:Windows -> Preference 步 ...
- Eclipse用法和技巧十八:减少不必要的输入
写代码的时候,很多人都有一个原则,尽量上输入.依靠IDE自动生成的代码,一般可读性,排版什么的都还是不错的,最主要的一般不会有什么低级错误.今天介绍几个在eclipse环境中,常用的依靠eclipse ...
- 分享最新15个加速 Web 开发的框架和工具(梦想天空)
我们为开发人员挑选了15个最新的 Web 开发框架,你肯定尝试一下这些新鲜的框架,有的可能略微复杂,有的提供了很多的配置选项,也有一些窗口小部件和界面交互的选择.他们将帮助你创建更优秀的网站,提供给 ...
- 最短路径A*算法原理及java代码实现(看不懂是我的失败)
算法仅仅要懂原理了,代码都是小问题,先看以下理论,尤其是红色标注的(要源代码请留下邮箱,有測试用例,直接执行就可以) A*算法 百度上的解释: A*[1](A-Star)算法是一种静态路网中求解最短路 ...
- windows live writer插件说明文档(附录网盘地址)
百度云地址:http://pan.baidu.com/s/1hqnjzjY 1.Screen Capture tool 用于直接在WLWriter中进行截图的一个插件,要配合SnagIt 这个软件使用 ...