HomePHP Moving Presentation Logic Out of Views with Code Igniter
Moving Presentation Logic Out of Views with Code Igniter
Manipulating views with CodeIgniter is a straightforward process. In a typical situation, there’s a model that fetches some rows from one or more database tables, and a view file that receives this data through a controller class, which is finally displayed on screen, generally in the form of an HTML page. However, CodeIgniter gives PHP programmers enough freedom to handle views in several useful ways, which can speed up the development of web applications. Therefore, if you’re taking your first steps with CI and wish to learn some handy approaches that will help you work with views in a truly painless fashion, then start reading this tutorial now!
At this point, after having introduced you to the subject of this series of articles, it’s time to recall the topics we discussed in the last tutorial, in case you still haven’t had the chance to read it. In summary, in that article I proceed to build a simple MySQL-driven application whose main task consisted of fetching some database rows and embedding this data into a basic view file.
Apart from playing a bit with the schema dictated by the Model-View-Controller pattern, this particular example showed in a nutshell how to return strings from the “$this->load->view()” method to create different parts of a web page, such as the typical header and footer sections, and a main area as well.
In addition, you’ll possibly recall that the view that displayed the database records implemented a simple presentation logic, reduced to looping over the records in question and nothing else. It’s also possible to make this view even “dumber” by moving this looping structure out of it, in this way achieving a greater level of separation between the application’s logic and its presentation layer.
Therefore, in this fifth part of the series, I’ll be rebuilding the web application that you learned in the last article, modifying the view file responsible for displaying database rows on the web page.
Do all these things sound interesting enough for you? Then let’s get started right now!