想用MVC的方式写一个小的CMS,建立了Controller、Model、View,但是不知道Controller向view传值应该怎么写?
index.php
show(); ?>testController.class.php
class testController{
function show(){
$testModel = new testModel();
$data = $testModel->get();
return $data;
}
}
testModel.class.php
require('database.php');
get_connection();
class testModel{
function get(){
$sql = "SELECT * FROM db_problem";
$res = mysql_query($sql);
return $res;
}
}
testView.php
BUG列表
ID
问题
提交时间
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
在controller里面把模板中的变量和值存在数据里面,file_get_content读取view视图文件内容,模板变量标识可以按照你喜欢的来,比如{$user}或{{user}},然后正则表达式匹配替换,最后输入echo
class Controller {
public $templateData = []; //保存模板文件的数据映射表
public function index(){
}
public function assign($key,$value){
}
public function display(){
}
}