即时通讯看着MVC模式,我可以在one example on phppatterns看到他们通过引用传递模型 - 在全局变量上做这件事的好处吗?我错过了明显的东西吗?通过引用传递的优点,反对使用全球?
class MyView extends View {
var $model;
function __construct(&$model){
$this->model =& $model;
}
function productTable($rownum=1) {
$rowsperpage='20';
$this->model->listProducts($rownum,$rowsperpage);
while ($product=$this->model->getProduct()) {
// Bind data to HTML
}
}
}
为什么你会这样做,因为使用全局变量?即
class MyView extends View {
global $model;
function __construct(){ }
function productTable($rownum=1) {
$rowsperpage='20';
$model->listProducts($rownum,$rowsperpage);
while ($product=$this->model->getProduct()) {
// Bind data to HTML
}
}
全局变量杀死小狗。这就是为什么。 – Matchu 2010-08-16 01:40:33