CodeIgniter Forums
Referring to parent model instance. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Referring to parent model instance. (/showthread.php?tid=53286)



Referring to parent model instance. - El Forum - 07-17-2012

[eluser]xerobytez[/eluser]
Hey guys, so I'm racking my brain over this. I've created a base model that has a lot of reusable code in it that I extend with several other models. I'd like to have some methods with the same name in both the parent model and child model, how would I properly refer to the method in the parent model from the child model if they are named the same. If I use $this->method() it refers to the method in the model its being called from, and I can't seem to get method chaining to work If I'm using parent:: since its static. Anyone have any ideas?


Referring to parent model instance. - El Forum - 07-17-2012

[eluser]Aken[/eluser]
Parent::method() doesn't necessarily mean that the method is static - you can use this just fine (CI uses it all over with the __construct() method). There's a perfect example of calling a parent method of the same name on PHP.net: http://www.php.net/manual/en/language.oop5.basic.php

If that doesn't help, post some of your code and explain what you're trying to do and what is actually happening.