Welcome Guest, Not a member yet? Register   Sign In
HMVC the right way ?!
#25

(06-01-2015, 08:13 AM)mwhitney Wrote:
(05-30-2015, 05:47 AM)Narf Wrote: Who said a library has to use a database? Or that it is a data access point at all?

You should be able to take a library, drop it in another application and work with it with no changes necessary. A model on the other hand is designed for a specific application. That's the only difference between the two.

I was going from the example code provided, which accessed a model to retrieve some data (which, in hindsight, could have been anywhere, but a database is often assumed when dealing with a model).

The biggest difference I see between libraries and models is that CI makes almost no assumptions about a library (except that there may be a config file with the same name which needs to be loaded and the result passed to the library's constructor), but assumes that a model will need access to CI itself (assuming you use CI_Model as a base) and that the database library may need to be loaded.

Because of these assumptions (made by the loader), and the somewhat-standard MVC roles in web applications, I prefer to avoid data access in libraries. However, in the event that a library needs to access data, I see no reason to shy away from loading a model to do so. Maybe we should inject the model or supply the data to the library's constructor, and those options should be considered when creating this type of interaction. We should also consider whether the functionality of the library in question should be part of a model rather than a library. The code, and how it's used, will usually pull you in one direction or the other.

Well, there's a significant difference between feeding data to a library and a library getting its data itself (by calling a model). The first case would be completely fine.
Reply


Messages In This Thread
HMVC the right way ?! - by RogerMore - 05-26-2015, 02:10 AM
RE: HMVC the right way ?! - by gadelat - 05-26-2015, 03:15 AM
RE: HMVC the right way ?! - by kilishan - 05-26-2015, 07:08 AM
RE: HMVC the right way ?! - by Narf - 05-26-2015, 01:16 PM
RE: HMVC the right way ?! - by kilishan - 05-26-2015, 10:32 PM
RE: HMVC the right way ?! - by mwhitney - 05-27-2015, 08:24 AM
RE: HMVC the right way ?! - by frocco - 05-27-2015, 12:18 PM
RE: HMVC the right way ?! - by mwhitney - 05-29-2015, 06:49 AM
RE: HMVC the right way ?! - by kilishan - 05-27-2015, 10:14 PM
RE: HMVC the right way ?! - by kilishan - 05-27-2015, 10:29 PM
RE: HMVC the right way ?! - by frocco - 05-28-2015, 05:47 AM
RE: HMVC the right way ?! - by mwhitney - 05-29-2015, 07:06 AM
RE: HMVC the right way ?! - by RogerMore - 05-28-2015, 12:06 PM
RE: HMVC the right way ?! - by josetrindade - 06-02-2015, 10:30 AM
RE: HMVC the right way ?! - by RogerMore - 05-29-2015, 07:24 AM
RE: HMVC the right way ?! - by kilishan - 05-29-2015, 07:30 AM
RE: HMVC the right way ?! - by mwhitney - 05-29-2015, 08:05 AM
RE: HMVC the right way ?! - by Narf - 05-29-2015, 09:50 AM
RE: HMVC the right way ?! - by mwhitney - 05-29-2015, 12:09 PM
RE: HMVC the right way ?! - by Narf - 05-30-2015, 05:47 AM
RE: HMVC the right way ?! - by mwhitney - 06-01-2015, 08:13 AM
RE: HMVC the right way ?! - by Narf - 06-01-2015, 10:21 AM
RE: HMVC the right way ?! - by no1youknowz - 06-01-2015, 08:33 PM
RE: HMVC the right way ?! - by RogerMore - 05-29-2015, 08:16 AM
RE: HMVC the right way ?! - by RogerMore - 05-31-2015, 01:48 PM
RE: HMVC the right way ?! - by frocco - 06-01-2015, 05:26 AM
RE: HMVC the right way ?! - by kilishan - 05-31-2015, 10:05 PM
RE: HMVC the right way ?! - by RogerMore - 06-01-2015, 10:49 AM
RE: HMVC the right way ?! - by mwhitney - 06-02-2015, 12:06 PM
RE: HMVC the right way ?! - by frocco - 06-01-2015, 12:02 PM
RE: HMVC the right way ?! - by RogerMore - 06-01-2015, 03:12 PM
RE: HMVC the right way ?! - by frocco - 06-03-2015, 03:41 AM
RE: HMVC the right way ?! - by RogerMore - 06-01-2015, 10:25 PM
RE: HMVC the right way ?! - by no1youknowz - 06-02-2015, 09:09 AM
RE: HMVC the right way ?! - by RogerMore - 06-03-2015, 12:40 AM
RE: HMVC the right way ?! - by mwhitney - 06-03-2015, 06:28 AM



Theme © iAndrew 2016 - Forum software by © MyBB