【发布时间】:2009-10-31 19:18:55
【问题描述】:
class Controller {
protected $_controller;
protected $_action;
protected $_template;
public $doNotRenderHeader;
public $render;
function __construct($controller, $action) {
$this->_controller = ucfirst($controller);
$this->_action = $action;
$model = ucfirst($controller);/* Conecting the model class*/
$this->doNotRenderHeader = 0;
$this->render = 1;
$modelName = ucfirst($model).'Model';
new $modelName;
$this->_template = new Template($controller,$action);
}
function set($name,$value) {
$this->_template->set($name,$value);
}
function __destruct() {
if ($this->render) {
$this->_template->render($this->doNotRenderHeader);
}
}
}
我是一个使用类的新手,我不太了解,我想实现并学习使用这个 mvc 结构示例的类,但是我有一个问题,我是函数集保存到数组中,一些信息然后发送到类模板内部,当我使用内部函数 __construct 时,我使用 set() 函数发送,该函数具有将数据保存到 $this_template 对象的作用,它工作正常,但是当我在此类或扩展类中创建新函数不起作用...
问题是 - 当我在 Controller 类中创建一个函数时,如何在数组中设置我需要的值,以便在类模板中使用它们:) 非常感谢您的帮助..对不起我的英语
class Template {
protected $variables = array();
function set($name,$value) {
$this->variables[$name] = $value;
}
function render(){
extract($this->variables); print_r($this->variables);
}
}
我需要使用类控制器中的函数 set() 来导出类模板中的数据,以及为什么当我在类控制器中创建函数时 例如:
function functionName() {
$data=array('a','b');
$this->set('data',$data);
}
在class Template里面,我放print_r($this->variables);,数组是空的
【问题讨论】:
-
您的问题是什么?我不明白。
-
看看 az Zend Framework 以了解 PHP 中的 MVC
-
我没有那么多时间,我正在做一个项目.. 而此时我正在研究 mvc 结构并使用类
-
你用蹩脚的英语问了一些非常含糊的问题。如果您发布您想要开始工作的代码、您想要做什么以及为什么它不起作用,这将有所帮助。然后我们就会更好地了解发生了什么。
-
好的,我会尽量写得更明确一些