3.1.2 MVC模式和URL访问

来源:互联网 发布:支持xen的linux内核 编辑:程序博客网 时间:2024/06/06 07:37
本节课大纲:一、什么是MVC                 //了解M -Model 编写model类 对数据进行操作 使用Model类 来操作数据V -View  编写html文件,页面呈现C -Controller 编写类文件(UserAction.class.php)二、ThinkPHP的MVC特点         //了解三、ThinkPHP的MVC对应的目录   //了解M 项目目录/应用目录/Lib/ModelC:\wamp\www\thinkphp\Home\Lib\ModelV 项目目录/应用目录/TplC:\wamp\www\thinkphp\Home\TplC 项目目录/应用目录/Lib/ActionC:\wamp\www\thinkphp\Home\Lib\Action命名: xxAction.class.phphttp://localhost:8080/thinkphp/index.php/Index/index  访问Index模块下的index 方法四、url访问C                  //了解五、url的4种访问方式          //重点!1.PATHINFO 模式 -- 重点!!!!!!http://域名/项目名/入口文件/模块名/方法名/键1/值1/键2/值2http://localhost/thinkphp/index.php/Index/show2.普通模式http://域名/项目名/入口文件?m=模块名&a=方法名&键1=值1&键2=值23.REWRITE模式http://域名/项目名/模块名/方法名/键1/值1/键2/值24.兼容模式http://域名/项目名/入口文件?s=模块名/方法名/键1/值1/键2/值2http://localhost/thinkphp/ 访问的是index.php 主入口文件http://localhost/thinkphp/index.php/Index/index                                     模块/方法C:\wamp\www\thinkphp\Home\Lib\Action 默认模块IndexAction.class.php比如要创建用户模块UserAction.class.phpclass 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=jjhttp://localhost/thinkphp/index.php/Index/show/name/jjhttp://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/xxxhttp://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=3321http://localhost:8080/thinkphp/index.php/Index/test/name/yyy/age/31313444//开启调试模式,关闭缓存 define('APP_DEBUG',true);   REWRITE模式 开启REWRITE,

0 0
原创粉丝点击