pbootcms后台MVC添加
时间 :
2022-08-10
编辑 :超级管理员
后台MVC添加
路径:apps\admin\ (MVC)
创建一个新的控制器
namespace app\admin\controller;use core\basic\Controller;use app\admin\model\TestModel;class TestController extends Controller{
private $model;
public function __construct()
{
$this->model = new TestModel();
}
public function index()
{
$result=$this->model->index();
$this->assign('testData', $result);//向页面传值
$this->display('test/test.html');//渲染页面
}
}创建一个新的model
namespace app\admin\model;use core\basic\Model;class TestModel extends Model{
public function index(){
// 执行查询
$result = parent::table('test')->field('name,phone')
->where('id=1')
->find();
return $result;
}}创建一个新的view
<!DOCTYPE html><html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<h1>测试页</h1>
<div>
<!-- 循环打印 -->
{foreach $testData(key,value)}
[key]
{/foreach}
<!-- 直接打印 -->
{$testData->name}
</div>
</body></html>
