我有一个问题,我一直在制作自己的 MVC 应用程序,但在模型和控制器之间传递变量似乎存在问题。控制器的输出是包含一些 json 格式数据的单个变量,看起来很简单。
控制器
<?php
class controllerLib
{
function __construct()
{
$this->view = new view();
}
public function getModel($model)
{
$modelName = $model."Model";
$this->model=new $modelName();
}
}
class controller extends controllerLib
{
function __construct()
{
parent::__construct();
}
public function addresses($arg = false)
{
echo'Addresses '.$arg.'<br />';
$this->view->render('addressesView');
$this->view->showAddresses = $this->model->getAddresses();
}
}
?>
看法
<?php
class view
{
function __construct()
{
}
public function render($plik)
{
$render = new $plik();
}
}
class addressesView extends view
{
public $showAddresses;
function __construct()
{
parent::__construct();
require 'view/head.php';
$result = $this->showAddresses;
require 'view/foot.php';
}
}
?>
现在的问题是 $this->showAddresses 没有传递给视图并且我卡住了。