我一直在用PHP开发定制的MVC。它是从头开始做的,但我遇到了一个问题:
我的视图控制器非常简单,但当我调用方法products()
时,它会无限次地包含视图乘积。是什么原因造成的?
//this is the autoload method in view controller
public function __autoload()
{
for ( $i=0; $i < count($this->include_files); $i++ )
{
require 'views/' . $this->include_files[$i] . '.php';
}
}
//this is the products method in view controller
public function products()
{
$this->include_files[0]='header';
$this->include_files[1]='navigation';
$this->include_files[2]='products';
$this->include_files[3]='footer';
$this->__autoload();
}
我在这里做错了什么?
感谢@ofir Baruch当我使用foreach 时,你的问题已经得到了答案,效果很好
public function __autoload() {
foreach($this->include_files as $file)
require 'views/'.$file. '.php';
}