testController.php
<?php
require("TestModel.php");
class testController{
/**
*学生模块控制器类
*/
public function testlist(){
//实例化模型,取出数组
$te=new TestModel();
$data=$te->getAll();
// 载入视图
require "testlist.html";
}
/**
* 查看指定的test信息
* @return
*/
public function testinfo(){
$id=$_GET['id'];
$te=new TestModel();
$data=$te->getById($id);
require "testinfo.html";
}
}
view层的testlist.html
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php var_dump($data);?>
</body>
</html>
view层的testinfo.html
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php var_dump($data); ?>
</body>
</html>
入口文件index.php
<?php
require "testController.php";
$obj=new testController();
echo "<pre>";
if (!empty($_GET)) {
$obj->testinfo();
}else{
$obj->testlist();
}
地址栏访问入口文件,根据是否带参数,或者是带不同的参数,即可访问不同的控制器中的方法了。