Professional CodeIgniter

(singke) #1

Chapter 3: A 10,000 - Foot View of CodeIgniter


69


function search(){
//use this for the search results
}

function about_us(){
//use this for the about_us page
}

function contact (){
//use this for the contact page
}

function privacy(){
//use this for the privacy page
}
}

As the project progresses, you ’ ll spend more and more time in the controller, loading models, using
libraries, and loading views as appropriate.


Before creating your views, you will need to do a bit of work on the index() function. Although you
haven ’ t created any views, you already have some design considerations in mind:



  1. You need to load the navigation.

  2. You need to load a template and reuse that template as often as possible.

  3. At some point, you ’ ll need to consider the use of subtemplates that are included in the master
    template.


You can ’ t do anything about the third point at the moment, but you can do something about the other
two. Create your index() function controller like this:


function index(){
$data[‘title’] = “Welcome to Claudia’s Kids”;
$data[‘navlist’] = $this- > MCats- > getAllCategories();
$this- > load- > vars($data);
$this- > load- > view(‘template’);
}

Here ’ s what will happen when you visit the home page of your site:


$data[ ’ title’] will be used as $title in the template view.

The categories from the database are retrieved into $data[‘navlist’] by the MCats model,
and then passed along to the underlying view.

The footer, header, and navigation subviews don ’ t need to be loaded here, as they ’ ll be loaded
inside the template.php view.



Free download pdf