Correcting teacher:天蓬老师
Correction status:qualified
Teacher's comments:
1.MVC框架大体可分为model、view、controller,这三块主要都是类、对象的应用和扩展
2.关于composer组件是对PHP代码模块化的一种形式,代码封装,再利用;
3.MVC框架整体构架没有变化,只是在MVC的架构中添加了composer组件管理器,来方便添加组件功能;
4.对于框架可以整体理解为三部分:MVC框架部分{app和core}和组件部分{vendor和composer.json、composer.lock}以及入口文件;
5.MVC框架重点理解:命名空间和自动加载之间的关系;往往出问题都在自动加载这块,自动加载出问题:往往跟命名空间、类名称和文件路径不一致导致;注意:\
和/
的使用场景
1.文件目录
2.json文件中自动加载配置项
{
"name": "ldy/frame",
"description": "MVC小框架",
"require": {
"catfan/medoo": "^1.7",
"league/plates": "^3.4"
},
//自动加载配置项
"autoload": {
"psr-4": {
"app\\Controllers\\": "app/Controllers",
"app\\Models\\": "app/Models",
"app\\View\\": "app/View",
"core\\": "core"
}
}
}
3.控制类代码
<?php
namespace app\Controllers;
use app\Models\StaffsModel;
use core\View;
class StaffsController
{
private $model=null;
private $view=null;
public function __construct(StaffsModel $model,View $view){
$this->model=$model;
$this->view=$view;
}
public function index(){
$data=$this->model->select("v_staffs",["id","name","age","gender","salary","email","postion","area"],["LIMIT"=>10]);
echo $this->view->render("index",["rows"=>$data]);
}
}
4.入口文件代码
<?php
use app\Controllers\StaffsController;
use app\Models\StaffsModel;
use core\View;
include __DIR__."/vendor/autoload.php";
$model=new StaffsModel();
$view=new View("app/View/staffs");
(new StaffsController($model,$view))->index();
5.运行结果图