Professional CodeIgniter

(singke) #1

Chapter 1: Welcome to the MVC World


18


displays
data for loads index()

runs fetchHomePage() loads

loads

user


view controller


model


Figure 1-5

A Slightly Different Approach: Templates


Along with standard PHP templates, CodeIgniter offers a lightweight template parser. To use the parser,
all you have to do is load it into your controller and pass in the data from the model. The view would
then use pseudo - variables instead of actual PHP variables, thus making your views free of PHP
altogether. If you are familiar with SMARTY templates, you will see that these pseudo - variables and
pseudo - structures align with your expectation of how the SMARTY world works. If you are new to this
type of template parsing, you won ’ t have any direct experience with it, but it ’ s pretty easy to pick up.
For example, instead of calling $title as you did before, you ’ d use {title}. Semantically, the
structures and naming conventions are similar enough to the PHP variables and structures that you
won ’ t have much trouble following along.

One final note before continuing the discussion: There ’ s normally no need to modify the model if you ’ re
going to work with the template parser. Why not? Well, it just so happens that the template parser will
accept the data structures you give it. The only thing that changes is how you call out and use the data
structure from the parsed template.
Free download pdf