• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Models, where, when and why?

#1
Question 
Hello all,

I've been using CI for a while now, but have the slight suspicion I'm missing the point about models. I've never used them. Now I'm starting a new project, and want to make sure I should or shouldn't use them.

I know what the VC part in MVC stands for. Views show things, Controllers make sure the views have something to work with. But what do Models do?

My point is, what can Models do that I can't achieve with a library? Up to now, I've been using libraries as CI-replacement for classes, which I used when I programmed Object Oriented PHP without framework. This has been going well, no issues there. But I've also read somewhere that libraries are mostly used for classes that can be used for multiple projects, like an email class or something. Is it a class which is related to a specific project, you should use a Model.

But in other threads and documentation, Models are only used for database-related tasks (which is fairly close to what a Model should do, judging by the definition of a Model in an MVC). So get, insert, update, delete kind of thing. For instance, getting the contents of a blogpost could be done by using
PHP Code:
$blog->get_post_by_id(24
.

Then this is usually returned as a basic result, using
Code:
$query->result();

This gives you an array with the contents of that blog-post, which you can pass through your Controller to the View in which it is outputted. But it isn't stored in an object of a class, so apart from passing it through, there's nothing you can do with it.

Does that mean that I should have a Model and a library for the same blogpost? So that my Controller creates an object from a library, and that library loads the corresponding Model? Then the library calls upon the Model to get the data from the database, which is then stored in the library-object, which is used by the Controller to pass through to the View? Doesn't that mean double work, having to create nearly identical versions of a blog-post, both as a Model and a library?

So yes, I'm confused. Online I can't find a proper answer to my confusion. With the start of a new forum here, I though someone would be inclined to either point me (and future candidates) to the right direction, or elaborate themselves.

Thanks in advance!
Reply


Messages In This Thread
Models, where, when and why? - by Thyrosis - 10-24-2014, 12:03 AM
RE: Models, where, when and why? - by Rufnex - 10-24-2014, 02:39 AM
RE: Models, where, when and why? - by navotjer - 10-24-2014, 04:10 AM
RE: Models, where, when and why? - by InsiteFX - 10-24-2014, 04:44 AM
RE: Models, where, when and why? - by kilishan - 10-24-2014, 08:17 AM
RE: Models, where, when and why? - by Thyrosis - 10-25-2014, 02:16 AM
RE: Models, where, when and why? - by John_Betong - 10-24-2014, 10:04 AM
RE: Models, where, when and why? - by Hobbes - 10-29-2014, 06:41 AM
RE: Models, where, when and why? - by jlp - 10-29-2014, 08:50 PM
RE: Models, where, when and why? - by albertleao - 10-30-2014, 11:41 AM
RE: Models, where, when and why? - by InsiteFX - 10-30-2014, 04:28 PM
RE: Models, where, when and why? - by Thyrosis - 11-01-2014, 01:27 AM
RE: Models, where, when and why? - by alroker - 11-16-2014, 11:55 AM
RE: Models, where, when and why? - by Thyrosis - 11-18-2014, 05:51 AM
RE: Models, where, when and why? - by RobertSF - 11-20-2014, 08:19 PM
RE: Models, where, when and why? - by veedeoo - 11-17-2014, 09:04 PM
RE: Models, where, when and why? - by bclinton - 11-17-2014, 09:32 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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