Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php mvc视图多次加载_Php_Model View Controller - Fatal编程技术网

php mvc视图多次加载

php mvc视图多次加载,php,model-view-controller,Php,Model View Controller,我一直在用PHP开发一个定制的MVC。它是从零开始制作的,但我遇到了一个问题: 我的视图控制器非常简单,但当我调用方法products()时,它无限次地包含视图产品。这可能是什么原因造成的 //this is the autoload method in view controller public function __autoload() { for ( $i=0; $i < count($this->include_files); $i++ ) {

我一直在用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();
}
//这是视图控制器中的自动加载方法
公共函数自动加载()
{
对于($i=0;$iinclude_文件);$i++)
{
需要“视图/”。$this->include_文件[$i]。.php';
}
}
//这是视图控制器中的products方法
公共功能产品()
{
$this->include_文件[0]='header';
$this->include_文件[1]=“导航”;
$this->include_文件[2]=“产品”;
$this->include_文件[3]='footer';
$this->uu autoload();
}
我做错了什么?

谢谢@ofir Baruch 当我使用foreach时,你的问题有了答案,它工作得很好

public function __autoload() {
        foreach($this->include_files as $file)
        require 'views/'.$file. '.php';
    }

你能在
for
循环之前写下
var\u dump($this->include\u files)
的输出吗。顺便问一下,为什么不使用foreach呢?这是output@OfirBaruch数组(4){[0]=>string(6)“header”[1]=>string(10)“navigation”[2]=>string(8)“products”[3]=>string(6)“footer”}@engr.waqas,我稍微编辑了一下这个问题。请确保我在“翻译”中没有犯任何错误。