[eluser]imn.codeartist[/eluser]
[quote author="diego.c" date="1261038590"]Hi all!
It's my first time with CI. Always i build my apps writing all the code!
So, I found a problem accidentally when I was writing a class. I'm not sure it's a bug, maybe the admin will have to move this topic to another category.
The problem is simple.
I have this code:
Code:
class A extends Model {
function A()
{
// Call the Model constructor
parent::Model();
$this->load->model('B');
}
}
class B extends Model {
function B()
{
// Call the Model constructor
parent::Model();
$this->load->model('A');
}
}
So, A load B and B load A.
This launch this error:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 261900 bytes) in C:\xampp\htdocs\prestamit\system\codeigniter\Base5.php on line 154
An infinite loop.
Maybe it's wrong to load a model from another model.
It's a bug?
Thank you! Cheers.[/quote]
The code you have done here is not a bug its illogical and you should never do that.
To solve this problem, you can create Wrapper where you can write your common code in one class and inherit them in all desired classed.
for example
Code:
class Master extends Model
{
function Master()
{
// Call the Model constructor
parent::Model();
}
// Write your desired common code in this model
}
class A extends Master{
function A()
{
// Call the Model constructor
parent::Master();
}
}
class B extends Master{
function B()
{
// Call the Model constructor
parent::Master();
}
}
For more information, please search in the net for Object Oriented Design Patterns