[eluser]k2zs[/eluser]
Wow!!!
I think I'm getting it...
My new controller:
Code:
<?php
class Home
extends Controller {
function Home() {
// load controller parent
parent::Controller();
// load helpers here
}
// load views sequentially
function index() {
//Model test
$this->load->model('main_model');
$data['mainNav'] = $this->main_model->getMainNav();
$data['subNav'] = $this->main_model->getSubNav();
$data['page'] = $this->main_model->getPage();
$this->load->view('template_view', $data);
}
}
My new model:
Code:
<?php
// Model
// DB query to get all active page titles to view in nav
class Main_model extends Model {
function getMainNav() {
$this->db->order_by('ParentID', 'asc');
$this->db->order_by('pgNavOrder', 'asc');
$this->db->where('pgActive', 1);
$this->db->where('ParentID', 0);
$q = $this->db->get('pages');
if($q->num_rows() > 0) {
foreach ($q->result() as $row) {
$data[] = $row;
}
return $data;
}
}
function getSubNav()
{
$this->db->order_by('ParentID', 'asc');
$this->db->order_by('pgNavOrder', 'asc');
$this->db->where('pgActive', 1);
$this->db->where('ParentID !=', 0);
$q = $this->db->get('pages');
if($q->num_rows() > 0) {
foreach ($q->result() as $row) {
$data[] = $row;
}
return $data;
}
}
function getPage() {
if ($this->uri->total_segments() <> 0) {
$this->db->where('pgName', $this->uri->segment(1));
} else {
$this->db->where('ParentID', 0);
$this->db->where('pgNavOrder', 1);
}
$q = $this->db->get('pages');
if($q->num_rows() > 0) {
foreach ($q->result() as $row) {
$data[] = $row;
}
return $data;
}
}
}
The if in the "getPage" method seems a bit messy, I'm sure there are probably better ways of doing it but it works for now. Now I just need to figure out how to pass the pages parentID from "getPage" to "getSubNav" in the model...
This stuff is GREAT!!