CodeIgniter Forums

Full Version: Parent class to call children method
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Unknown[/eluser]
Is it possible to call child class method from parent class method, normally in OOPS concept we declare the parent class as virtual and I think this provides the method to call child class method from parent class. Please help me out to accomplish this in codeignitor.
Actually My intension is to have a common function dealing with the insertion of the form.
I have a master controller where take a function and the arguments to this function is the controller name,so i need to route to call other controller from my master controller.

El Forum

[eluser]WanWizard[/eluser]
If you have this situation, there's a flaw in your class design.

If you want this, define the parent class as abstract, and the method as abstract in the parent class, to force it to be available in the child, and to force a child to be present.
When you do this, you can just use $this->method() in any parent method, which will call the method defined in the child.

In the CI architecture, if you have a common method, you should store this in a library. Also, CI by default does not support controllers calling controllers...