Welcome Guest, Not a member yet? Register   Sign In
Explaination of "parent::Model();" and "parent::Controller();"
#1

[eluser]Casperlarsen94[/eluser]
Hi everyone,

i'm started to learn Codeigniter, and at this time i'm reading user guide.
But i have a problem,

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

I don't understand what this do:
Code:
parent::Controller();
Code:
parent::Model();

Can someone please help me explain what it's do?

Kind regards,
Casper
#2

[eluser]Buso[/eluser]
You use that when you want to overload the constructor (change its functionallity). Most of the times, you want your new constructor to do the same as the old constructor + new stuff. So you call the parent constructor, and then you add the new stuff.

In your case, Model() and Controller() are the constructors's names.

Read more about OOP (object oriented programming) if you didn't understand what I said, as this isn't something specific to Codeigniter.
#3

[eluser]umefarooq[/eluser]
This is called inheritance a simple example is from a family Father,Mother and kids you can say Controller is Father and model is mother and kids are models and controller, every kid has his own habits and abilities some are inherited from parent that why parent::Controller() or parent::Model() is called, Father can play only guitar, Mother can dance ,son can sing and play guitar and he can dance also, here inherited things are dance and guitar. same as in Programming inheritance let you do the same thing you call parent common methods and properties to use in child classes, write once use multiple time. for more detail on OOP read this OOP concepts

http://java.sun.com/docs/books/tutorial/...index.html
#4

[eluser]Buso[/eluser]
I want to make clear that you don't need to call parent::Model() to inherit its constructor

I'm always seeing constructors like this one:

Code:
function __construct() {
  parent::__construct();
}

Which makes no sense, unless you intend to add something to it, because if you don't overload it, it is inherited by default anyway




Theme © iAndrew 2016 - Forum software by © MyBB