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!