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
Zoe ZoeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Marco GasiFreelancerCommented:
Look at system folder: there you find Controller.php and Model.php.

Parent constructor method for controllers:
	/**
	 * Class constructor
	 *
	 * @return	void
	 */
	public function __construct()
	{
		self::$instance =& $this;

		// Assign all the class objects that were instantiated by the
		// bootstrap file (CodeIgniter.php) to local class variables
		// so that CI can run as one big super object.
		foreach (is_loaded() as $var => $class)
		{
			$this->$var =& load_class($class);
		}

		$this->load =& load_class('Loader', 'core');
		$this->load->initialize();
		log_message('info', 'Controller Class Initialized');
	}

Open in new window


Parent contructor method for models:
	/**
	 * Class constructor
	 *
	 * @return	void
	 */
	public function __construct()
	{
		log_message('info', 'Model Class Initialized');
	}

Open in new window


As you can see, models don't need to inherit anything by their parent constructor whereas controllers do.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ray PaseurCommented:
A constructor is just like any other method.  It only differs in that it is called once automatically when an object is instantiated from the class.  

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.
0
Loganathan NatarajanLAMP DeveloperCommented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.