```

3. 控制器(Controller)

我们创建一个名为`Controller.php`的控制器文件,用于处理用户请求和调用模型和视图。

```php

require 'Post.php';

require 'index.php';

class Controller {

private $posts;

public function __construct() {

$this->posts = new Post();

}

public function index() {

$allPosts = $this->posts->getAllPosts();

require 'index.php';

}

public function show($id) {

$post = $this->posts->getPostById($id);

if ($post) {

require 'show.php';

} else {

echo 'Post not found!';

}

}

public function create() {

// Handle create post form submission

}

public function update($id) {

// Handle update post form submission

}

public function delete($id) {

$this->posts->deletePost($id);

header('Location: index.php');

}

}

>

```

通过以上实例,你可以了解如何在PHP中使用MVC模式建立模型。你可以根据需要修改和扩展这个实例,以构建更复杂的PHP应用程序。