Welcome Guest, Not a member yet? Register   Sign In
Models, where, when and why?
#7

Thanks to all for the replies. I think I can safely assume that even here there is no "should" and "shouldn't" and that it is a matter of personal preference or company policy.

(10-24-2014, 08:17 AM)kilishan Wrote: To me, the point of the model is to hold the business logic of the data. That includes getting the data from the database, and then ensuring that any application-specific processing is done there also. Like if you need to ensure that post titles are always ucwords you could enforce that in the model. (Yes, that's a fairly silly example...)

No, that's no silly example at all. It is things like those that got me confused in the first place. Because uppercasing the post-title has nothing to do with the database, it's the title of a post (an object in my opinion). I would expect functionality like that in a library, not in a Model.

Think about this one. I have two classes. User and Post. A Post is made by a User. So in the post-table, a field 'user' is active, which holds the userid of the User who posted the Post.

But, when I pull up the Post to use in a View, I don't want Post->user to hold the userID, I want it to hold a User. So Post->User->name will give me the username.

Also, I have a class Category. A Post belongs to a Category. So under Post->category I don't want to see the categoryID, but I want it to hold a Category object.

I think I'm gonna stick with using libraries to work situations like that, but just for the sake of clarity: how would I go about that using Models? Can you have Model include a Model like this?

John_Betong Wrote:When returning data from a Model (also applies to Controllers and Libraries) it is tempting to Html format the data with size, bold, colours, etc. This is remarkably easy and seems such a good idea at the time but later becomes an onerous task to make changes to the View. It becomes necessary to sift through reams of Controller, Library of Model's script to find the offending output which is creating the View havoc!

Yeah, I figured that one out long time ago... The hard way. I'm guessing a lot of devs experienced this first hand too Big Grin
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



Theme © iAndrew 2016 - Forum software by © MyBB