以下是一个简单的PHP MVC模式实现示例,包括控制器(Controller)、模型(Model)和视图(View)。
| 类别 | 名称 | 功能描述 |
|---|---|---|
| Model | StudentModel | 负责处理学生数据 |
| Controller | StudentController | 负责处理用户请求,调用Model和View |
| View | StudentView | 负责展示学生信息 |
StudentModel.php
```php

class StudentModel {
private $students;
public function __construct() {
$this->students = [
['id' => 1, 'name' => '张三', 'age' => 20],
['id' => 2, 'name' => '李四', 'age' => 21],
['id' => 3, 'name' => '王五', 'age' => 22]
];
}
public function getStudents() {
return $this->students;
}
}
>
```
StudentController.php
```php
require_once 'StudentModel.php';
class StudentController {
private $model;
private $view;
public function __construct() {
$this->model = new StudentModel();
$this->view = new StudentView();
}
public function index() {
$students = $this->model->getStudents();
$this->view->display($students);
}
}
>
```
StudentView.php
```php
class StudentView {
public function display($students) {
echo "
