abstract://入口文件 index.php//入口文件 index.php
require 'vendor/autoload.php';
define('PATH_NAME',__DIR__);
require 'cfg/base.php';
use cfg\base;
$config = require 'cfg/config.php';
$qStr = $_SERVER['QUERY_STRING'];
$base = new base($config,$qStr);
$base->setDebug();
echo $base->run();
//
//继承视图类 view.php
namespace cfg\exd;
use League\Plates\Engine;
class view extends Engine{
public function __construct(){
parent::__construct($directory = null, $fileExtension = 'php');
}
}
//继承数据库类 model.php
namespace cfg\exd;
use Medoo\Medoo;
class model extends Medoo{
public function __construct(){
$option = require 'cfg/config.php';
parent::__construct($option['Db']);
}
}
//构造控制器类 controller.php
namespace cfg\exd;
use cfg\exd\view;
class controller{
protected $view;
protected $data=[];
//构造控制器对象同时构造视图对象
public function __construct(){
//构造视图
$this->view = new view;
//设置视图目录
$this->setDirectory();
//设置视图别名
$this->addFolder();
}
//重载视图目录
public function setDirectory(){
$this->view->setDirectory(PATH_NAME.'/app/admin/view');
}
//重载视图别名目录
public function addFolder(){
$this->view->addFolder('admin',PATH_NAME.'/app/admin/view');
}
//重载视图渲染
public function render($path){
return $this->view->render($path,$this->data);
}
}
//控制器类 Index.php
namespace app\admin\controller;
use app\model\User;
use cfg\exd\controller;
class Index extends controller {
public function index(){
return 'my name is whyan20191020';
}
public function user(){
//声名模型对象
$users = new User;
//返回数据数组
$result = $users->select('m_users','*',['user_id[>]'=>3]);
//模板变量赋值
$this->data['title'] = 'welcome';
$this->data['result'] = $result;
//渲染模板
return $this->render('index/user');
}
}
//渲染user.php
=$title?>
echo '
'.var_export($result,true).'
';?>
Correcting teacher:天蓬老师Correction time:2019-10-21 16:31:38
Teacher's summary:QQ截图20191020230053.png //入口文件 index.php