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

[eluser]k2zs[/eluser]
I'm just not getting it. Can you explain the whole thing with actual file names? I have yet to be able to use a model. Where is the controller code calling the model? what is the actual model name? Here is what I did:

I have one controller called "main.php" and in it I have:

Code:
<?php
class Main
    extends Controller {

    function Main() {

        // load controller parent

        parent::Controller();

        // load helpers here

    }

    // load views sequentially

    function index() {
        
        // get the default page from the database
        $query = $this->db->query("SELECT * FROM pages WHERE (parentID =0 AND pgNavOrder =1 AND pgActive =1)");

        if ($query->num_rows() > 0)

        {
            $row = $query->row();

        // load 'header' view

        $this->load->view('header_view', array ( 'header' => $row->pgTitle ));
        
        
        //testing call to model
        $data['subNav_pages'] = $this->subNav_model->get_subNav_main();        
        $this->load->view('subnav_view', $data);

        // load 'main' view and pass in database content

        $this->load->view('main_view', array ( 'pageContent' => $row->pText ));

        } else {
            
        // load 'header' view

        $this->load->view('header_view', array ( 'header' => 'Page not found' ));

        // load 'content' view and pass in database content

        $this->load->view('main_view', array ( 'pageContent' => 'oops! the page you were looking for can not be found' ));
        
        }

        // load 'footer' view

        $this->load->view('footer_view', array ( 'footer' => 'created and maintained by <a href="http://www.tgcdesign.com" target="_blank">TGCDesign.com</a> | powered by <a href="http://www.codeigniter.com" target="_blank">CodeIgniter</a> ' ));
    }
    
    function page_lookup () {
        // get the default page from the database
        $this->db->where('pgName', $this->uri->segment(1));
        $query = $this->db->get('pages');
        
        if ($query->num_rows() > 0)
        {
        $row = $query->row();

        // load 'header' view

        $this->load->view('header_view', array ( 'header' => $row->pgTitle ));

        // load 'content' view and pass in database content

        $this->load->view('main_view', array ( 'pageContent' => $row->pText ));
        
        } else {

        // load 'header' view

        $this->load->view('header_view', array ( 'header' => 'Page not found' ));

        // load 'content' view and pass in database content

        $this->load->view('main_view', array ( 'pageContent' => 'oops! the page you were looking for can not be found' ));
        }

        // load 'footer' view

        $this->load->view('footer_view', array ( 'footer' => 'created by <a href="http://www.tgcdesign.com" target="_blank">TGCDesign.com</a> | powered by <a href="http://www.codeigniter.com" target="_blank">CodeIgniter</a> ' ));
    }
}

Then I have the model called "subNav_model.php" and in it I have:
Code:
&lt;?php
// Model
// DB query to get all active page titles to view in nav

function get_subNav_main()
    {
        $this->db->order_by('ParentID', 'asc');
        $this->db->order_by('pgNavOrder', 'asc');
        $this->db->where('pgActive', 1);
        $query = $this->db->get('pages');
        echo 'boo';
        return $query->result();
    }

I created the view to load the subNav and called it "subNav_view.php" and in it I have:
Code:
<div>
        &lt;?php foreach($subNav_pages->result() as $row):?&gt;
        &lt;?php echo $row->pgName;?&gt;
        &lt;?php endforeach;?&gt;
    </div>

When I try running it I get

Code:
A PHP Error was encountered
Severity: Notice

Message: Undefined property: Main::$subNav_model

Filename: controllers/main.php

Line Number: 13


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