Blogger Information
Blog 25
fans 0
comment 0
visits 15860
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
0801___MVC作业
杨发国的博客
Original
564 people have browsed it

Model.php

实例

<?php
/**
 模型类
// */
class Model
{
public $stmp;
private $pdo=null;
public $data=array();
public function getData()
{
    $this->pdo = new PDO('mysql:host=127.0.0.1;dbname=php', 'root', 'root');
    $stmp = $this->pdo->prepare('SELECT * FROM  `user`  WHERE  id>1 ');
    $stmp->execute();
    return $data=$stmp->fetchAll(PDO::FETCH_ASSOC);
}
}

运行实例 »

点击 "运行实例" 按钮查看在线实例

View.php

实例

<?php
class View
{
    public function fetch($data)
    {
        $table = '<table border="1" cellspacing="0" cellpadding="3" width="80%">';
        $table .= '<caption>用户信息表</caption>';
        $table .= '<tr bgcolor="#add8e6"><th>ID</th><th>姓名</th><th>年龄</th></tr>';

        // 遍历模型数据
        foreach ($data as $row) {
            $table .= '<tr>';
            $table .= '<td>' . $row['id'] . '</td>';
            $table .= '<td>' . $row['name'] . '</td>';
            $table .= '<td>' . $row['age'] . '</td>';
            $table .= '</tr>';
        }

        $table .= '</table>';

        return $table;
    }
}

运行实例 »

点击 "运行实例" 按钮查看在线实例

controller.php

实例

<?php
require 'Model.php';
require 'View.php';
class Controller
{
    public function index()
    {
        $model=new Model();
        $data = $model->getData();

       $view = new View();
       return $view->fetch($data);
    }
}
$controller = new Controller();
echo $controller-> index();

运行实例 »

点击 "运行实例" 按钮查看在线实例

QQ截图20190811225719.png

Correction status:qualified

Teacher's comments:好吧, MVC流程理解了就好
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post