In CodeIgniter I have a model named User_Model
and another one named Product_Model
Now in the User_Model
constructor I am loading couple of models that I use in the class.
class User_Model extends CI_Model
{
public function __construct()
{
parent::construct();
$this->load-model("Product_Model");
//load some more models I need...
}
}
While working on products, I need sometimes to be using the user model, so I do:
class Product_Model extends CI_Model
{
public function __construct()
{
parent::construct();
$this->load-model("User_Model");
//load some more models I need...
}
}
The problem is that since these are in circular reference, I am getting Fatal error: Maximum function nesting level of '100' reached
. I am using xdebug
and I know that it has settings to remove this. My question is - what is the correct way to handle this without increasing setting limitations. How should I restructure the architecture?
I know that if I am using PHP
without codeigniter
, and create circular references (class A loads class B, class B loads class A), PHP will load it for N times (I think it is three) and then mark it as *recursive*.
But we are faced with such a situation, what is the best way to refactor?