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

[eluser]@robertotra[/eluser]
Hello,
I have a doubt about models in CI. User Guide says they are optional, in the sense that database manipulation can be inserted also directly into controllers:

Quote:CodeIgniter has a fairly loose approach to MVC since Models are not required. If you don't need the added separation, or find that maintaining models requires more complexity than you want, you can ignore them and build your application minimally using Controllers and Views.

So, using models is just about following MVC conventions and improve code readability, usability and maintenance, as User Guide says:

Quote:Instead of writing database operations right in the controller, queries should be placed in a model, so they can easily be reused later.

Anyway, if it is possible to manage databases inside controllers without calling any model, and using models is just about moving code about databases into them, why it is required to call the parent constructor when creating a model? They do not even connect automatically (or by parameter sent to the constructor) to a database, so what is parent constructor for? User guide says:

Quote:Make sure your class extends the base Model class.
The file name will be a lower case version of your class name. For example, if your class is this:
Code:
class User_model extends CI_Model {

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

Cannot models simply be loaded as any other custom library? Which are the methods of the parent class that we use and/or may skip into our implementation of a model?

Thanks for your reply
Best regards
Roberto




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