when to use parent::__construct(); in the class?

#1
[eluser]Unknown[/eluser]
Dear all
I`ve started learning CI by the tutorial in the User Guide.
I found the News_model did not add the parent::__construct()
Code:
News_model extends CI_Model {
public function __construct()
...//
But the News controller starts with parent::__construct()
Code:
class News extends CI_Controller {

public function __construct()
{
  parent::__construct();
Could anyone kindly tell me the differences?
And whats the criteria of adding the parent::__construct() when creating the class?
Many thanks

#2
[eluser]CroNiX[/eluser]
You only need to add parent::__construct(), if you are doing something in your __construct().

just having
Code:
public function __construct()
{
  parent::__construct();
}

with nothing else doesn't do anything.

See: http://ellislab.com/codeigniter/user-gui...nstructors

#3
[eluser]Bart v B[/eluser]
In other words, if you are planning to do things only in that object, then you can reference that in your constructor.

#4
[eluser]jairoh_[/eluser]
to inherit directly the attributes of the parent class. Smile


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.