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:wampwww	hinkphpHomeLibModel
	
	V 项目目录/应用目录/Tpl
	
	C:wampwww	hinkphpHomeTpl
	
	
	C 项目目录/应用目录/Lib/Action
	
	C:wampwww	hinkphpHomeLibAction

	命名: 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:wampwww	hinkphpHomeLibAction 默认模块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,

原文地址:https://www.cnblogs.com/zhaoyangjian724/p/6199814.html