确定CodeIgniter控制器中的问题 [英] Determine problem in CodeIgniter controller
问题描述
我创建了一个基本控制器,所有的控制器扩展...
I've created a base controller that all of my controllers extend...
class PublicController extends CI_Controller {
private $js = array(),
$css = array(),
$templateVars = array();
public function __construct () {
parent::__construct();
//register account
$this->templateVars['account'] = ($this->account = $this->modelFactory('account'));
// enable profiler for development
if (ENVIRONMENT == 'development') {
$this->output->enable_profiler(true);
$this->addJs('jquery-min-1.5.2');
} else {
$this->addJs('http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js');
}
$this->addCss('base');
$this->addJs('base');
}
/**
* Loads and initiates models
*/
protected function modelFactory ($model, $input = array()) {
$this->load->model($model);
$class = $model.'Model';
return new $class($input);
}
这里的问题是我得到错误错误:达到最大功能嵌套级别100,中止!在第328行上的C:\Program Files(x86)\EasyPHP-5.3.6.0\www\site.com\system\core\Common.php中
The problem here is that I get the error Fatal error: Maximum function nesting level of '100' reached, aborting! in C:\Program Files (x86)\EasyPHP-5.3.6.0\www\site.com\system\core\Common.php on line 328
当我注释掉 $ this-> templateVars ['account'] =
行时,错误消失....
When I comment out the line $this->templateVars['account'] =
the error goes away.... how come this is looping?
推荐答案
作为解决方法,您可以将其添加为__construct方法中的第一个语句:
As a workaround you could add this as the first statement in your __construct method:
global $onlyonce; if ($onlyonce++) return;
这将阻止创建控制器的多个实例。不知道你的代码或CodeIgniter的其余部分,它可能假设你的模型类本身实例化你的控制器。这反过来又创建了另一个模型。
This will prevent multiple instances of your controller to be created. Without knowing the rest of your code, or CodeIgniter, it's likely to assume that your model class itself instantiates your controller. Which in turn creates another model.
一个xdebug剖析器跟踪将告诉你更多。这不是足够的代码来告诉你确切的原因。
A xdebug profiler trace will tell you more. This is not enough code to tell you the exact reason.
这篇关于确定CodeIgniter控制器中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!