Welcome Guest, Not a member yet? Register   Sign In
Why call parent constructor when creating a model?
#7

[eluser]@robertotra[/eluser]
[quote author="Aken" date="1327572591"]Including the constructor function in your models is optional. When you extend the CI_Model, it will automatically run CI_Model's constructor which will do the necessary connections to allow your model to use CodeIgniter's resources....[/quote]

I know, but the problem arises when you want to make your own constructor in the model, as example to load the database resource (unless you want to load it into the various controllers each time before you load the model, which I found not convenient). AS explained in the User Guide:

Quote:Connecting to your Database

When a model is loaded it does NOT connect automatically to your database.

Since extending the class CI_Model does not connect automatically to the database (rightly, because different models can connect to different databases) I found convenient loading the database into the Model's constructor instead than inside the controllers loading it, that's why I was wondering about calling also the parent constructor.


Messages In This Thread
Why call parent constructor when creating a model? - by El Forum - 01-25-2012, 07:26 AM
Why call parent constructor when creating a model? - by El Forum - 01-25-2012, 07:51 AM
Why call parent constructor when creating a model? - by El Forum - 01-25-2012, 07:57 AM
Why call parent constructor when creating a model? - by El Forum - 01-25-2012, 08:01 AM
Why call parent constructor when creating a model? - by El Forum - 01-26-2012, 12:34 AM
Why call parent constructor when creating a model? - by El Forum - 01-26-2012, 03:09 AM
Why call parent constructor when creating a model? - by El Forum - 01-26-2012, 03:27 AM
Why call parent constructor when creating a model? - by El Forum - 01-26-2012, 11:30 PM



Theme © iAndrew 2016 - Forum software by © MyBB