Professional CodeIgniter

(singke) #1

Chapter 4: Creating the Main Web Site


90


function getCategoriesNav(){
$data = array();
$this- > db- > where(‘parentid < ’, 1);
$this- > db- > where(status’, ‘active’);
$this- > db- > orderby(‘name’,’asc’);
$Q = $this- > db- > get(‘categories’);
if ($Q- > num_rows() > 0){
foreach ($Q- > result_array() as $row){
$data[$row[‘id’]] = $row[‘name’];
}
}
$Q- > free_result();
return $data;
}

These two simple changes in the getCategoriesNav() function result in a much simplified navigation,
as illustrated in Figure 4 - 5.

Figure 4 - 5

Now all you have to do to build the right view for categories (displaying either associated categories or
products) is to check for the existence of a parentid value.

Here is a bare - bones look at the controller function cat(). Notice the use of the if statement looking for
a parentid value. In a moment, you ’ ll be able to fill it in, but this should give you an idea of what ’ s going
to happen:
Free download pdf