Welcome Guest, Not a member yet? Register   Sign In
overall code organization: helper, library, core, or model?

CI v3 supports Composer if you enable it via a config value, so that would probably be your best bet for an autoloader, though it presumes the code you need to autoload is compatible with Composer.

I've used a number of static libraries with CI which simply include a non-static constructor for CI to call.

A helper is usually just a group of related function definitions with no class definitions. The libraries directory is more or less a catch-all for classes which do not have an easily-defined place in the MVC structure.

In my opinion, most of your examples would be libraries, but it really depends on the structure of the code itself and the way in which you would normally call the code. CI is very flexible in many ways, so different users can establish their code separation in different ways. The first three or four examples could just as easily be models, and in my own site I have a number of models involved in handling notifications, though the notifications themselves are triggered by various models (as part of an insert or update, for example) and even by a library in some situations (e.g. retrieve and display notifications when a user logs in).

There are nearly as many opinions on where to draw the line between a model and controller as there are sites using MVC (and each framework implements MVC in a way that reflects an opinion on where that line should be drawn). CI does tend to lend itself to fat controllers, and I will often start with a fat controller and thin it out over time (for instance, the data requirements for a given portion of the site may not be clear initially, so the model(s) may not be implemented until later). I tend to think that any repetition may be an indication that the repeated code is in the wrong place, but this doesn't always help clarify where the code should reside.

In your case, since much of the code may already be written, it may be best to start with setting up the routing and some controllers to interface with the existing code (utilizing an autoloader or wrapping the code into libraries and/or helpers).

Messages In This Thread
RE: overall code organization: helper, library, core, or model? - by mwhitney - 01-02-2015, 12:53 PM

Theme © iAndrew 2016 - Forum software by © MyBB