Welcome Guest, Not a member yet? Register   Sign In
New to programming and trying to understand it all.
#7

[eluser]Brandon Dickson[/eluser]
PHP uses a concept called 'overloading' to handle inheritance, so when you have a class that is inherited by another, the new class inherits all the properties and methods of the parent class, however, if a method or property is defined in the new class it 'overloads' the previous declaration.

In PHP the constructor method is just another method, so if you define it in the second class, nothing from the constructor in the first class gets called... unless you call parent::Class_name() (in PHP4 & 5) or parent::_construct() ( in PHP5 + )

In CI, the Controller's constructor method is used to create instances of other classes that are accessible from what ever controller is currently loaded ( $this->load->view() for example ), as well as calling a few other functions required for the system to work.

So if you create a constructor in your controller, you need to call parent::Controller(), inside it, to make sure that the required functions get called, and the required class instances are added to your controller.

Also note that if you don't define a constructor in a child class, the parent's controller is automatically called, when an instance of the class is created.

-Brandon


Messages In This Thread
New to programming and trying to understand it all. - by El Forum - 05-31-2008, 11:22 PM
New to programming and trying to understand it all. - by El Forum - 06-01-2008, 12:01 AM
New to programming and trying to understand it all. - by El Forum - 06-01-2008, 12:37 AM
New to programming and trying to understand it all. - by El Forum - 06-01-2008, 12:54 AM
New to programming and trying to understand it all. - by El Forum - 06-01-2008, 09:09 AM
New to programming and trying to understand it all. - by El Forum - 06-03-2008, 09:18 PM
New to programming and trying to understand it all. - by El Forum - 06-03-2008, 10:19 PM
New to programming and trying to understand it all. - by El Forum - 06-03-2008, 10:47 PM
New to programming and trying to understand it all. - by El Forum - 06-03-2008, 11:20 PM
New to programming and trying to understand it all. - by El Forum - 06-04-2008, 07:50 PM



Theme © iAndrew 2016 - Forum software by © MyBB