Welcome Guest, Not a member yet? Register   Sign In
Extended Views
#6

This is generally what leads some people to look for alternatives to MVC. In the end, most of them come down to some sort of three-tier architecture, in which the basic idea is to separate code related to the presentation (View), logic (Controller), and data (Model). Each architecture pattern addresses different levels of separation between the three, primarily centered around whatever environment the pattern was initially created for.

MVC was not created for web applications, but has been widely adopted by web developers, so there are some widely divergent ideas about what goes where in the MVC pattern, and at this point, especially in the PHP world, it's largely based on the framework and the individual development team's preferences.

In a CodeIgniter project, I would generally create a library (or multiple libraries) to handle code like this. In other words, your Controller loads a library to take some data and generate some HTML which you'll then pass to your View for display, or your Controller loads a library which it makes available to your View, and your View passes data to the library to generate HTML which the View will display.

In some cases, the library might be used only by one or two Views, or all of the Views loaded by a certain Controller, or all of the Views which work with data from a certain Model. In other cases, the library might be used by most of the Views in your application.

In your case, though, it may be perfectly acceptable to have more code in a View than may be the case for others. If the code does little more than generate HTML (or some other display format) from some form of input, there's little need for it to exist anywhere other than a View.

I would avoid PHP includes in a view. At that point, you're just abandoning all hope of separation of concerns, as this implies that you know the location of the file to be included, either relative to the current file's location or as an absolute location and that the content of the file is appropriate to be included wherever it is that you've decided to include the file. Even though CodeIgniter doesn't utilize any of the PSRs, I would defer to PSR-1 section 2.3's discussion of what should be included in a given file:

Quote:A file SHOULD declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it SHOULD execute logic with side effects, but SHOULD NOT do both.
Reply


Messages In This Thread
Extended Views - by ad11 - 09-13-2015, 04:23 PM
RE: Extended Views - by PaulD - 09-15-2015, 04:09 PM
RE: Extended Views - by ad11 - 09-15-2015, 07:04 PM
RE: Extended Views - by mwhitney - 09-16-2015, 08:09 AM
RE: Extended Views - by ad11 - 09-16-2015, 11:32 AM
RE: Extended Views - by mwhitney - 09-16-2015, 01:06 PM
RE: Extended Views - by ad11 - 09-22-2015, 02:25 PM
RE: Extended Views - by mwhitney - 09-23-2015, 07:19 AM
RE: Extended Views - by cartalot - 09-23-2015, 03:01 PM



Theme © iAndrew 2016 - Forum software by © MyBB