Zoe Zoe
asked on
constructor - CodeIgniter
Can anyone tell me why is the constructor in news.php using parent::__construct ? I only know it is because this is to use the method in parent class which is within CI_Controller.
If so, why is the constructor in news_model.php not using parent::__construct?
News.php
News-model.php
If so, why is the constructor in news_model.php not using parent::__construct?
News.php
News-model.php
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If so, why is the constructor in news_model.php not using parent::__construct?
As for my knowledge it is implemented to limit such idea from model constructor where controller does. I agree with @Marco Gasi comments
As for my knowledge it is implemented to limit such idea from model constructor where controller does. I agree with @Marco Gasi comments
In the general sense, calling parent::__construct() is just calling a function (method) to get some piece of work done. Different programming objectives may need different approaches. If the child class needs the parent's constructor to run before it can do its work, calling the parent constructor makes sense. If this is not needed (for example, the child simply adds some static functionality) then there is no reason to call the "upstream" constructors or other methods.