Welcome Guest, Not a member yet? Register   Sign In
New to CI (be kind)
#8

[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!!


Messages In This Thread
New to CI (be kind) - by El Forum - 10-24-2010, 11:31 AM
New to CI (be kind) - by El Forum - 10-24-2010, 11:55 AM
New to CI (be kind) - by El Forum - 10-24-2010, 12:38 PM
New to CI (be kind) - by El Forum - 10-24-2010, 07:45 PM
New to CI (be kind) - by El Forum - 10-24-2010, 09:32 PM
New to CI (be kind) - by El Forum - 10-24-2010, 10:36 PM
New to CI (be kind) - by El Forum - 10-25-2010, 07:46 AM
New to CI (be kind) - by El Forum - 10-25-2010, 11:44 PM



Theme © iAndrew 2016 - Forum software by © MyBB