Welcome Guest, Not a member yet? Register   Sign In
newbie need ur help!!
#8

[eluser]iConTM[/eluser]
you can load multiple views in one controller.

you can see a controller as a category or directory

Code:
<?php

class Articles extends Controller {

    function Articles ()
    {
        parent::MY_Controller();
        #load model to access article data (models/article_model.php)
        $this->load->model('Article_model');
    }

    // accessed by '/articles'
    function index()
    {
        $this->latest();
    }

    // accessed by '/articles/article/id'
    function article ($id)
    {
        #collect data for view
        $data['title'] = 'Some title'
        $data['article'] = $this->Article_model->get_article($id);
        #show the view (views/single-article.php)
        $this->load->view('single-article', $data);
    }

    // accessed by '/articles/latest'
    function latest()
    {
        #collect data for view
        $data['title'] = 'Some title' // view data
        $data['articles'] = $this->Article_model->get_latest_articles();
        #show the view (views/all-articles.php)
        $this->load->view('all-articles', $data);
    }

}

/* End of file articles.php */
/* Location: ./system/application/controllers/articles.php */


Messages In This Thread
newbie need ur help!! - by El Forum - 06-20-2010, 04:47 AM
newbie need ur help!! - by El Forum - 06-20-2010, 05:23 AM
newbie need ur help!! - by El Forum - 06-20-2010, 05:35 AM
newbie need ur help!! - by El Forum - 06-20-2010, 06:09 AM
newbie need ur help!! - by El Forum - 06-20-2010, 08:31 AM
newbie need ur help!! - by El Forum - 06-20-2010, 03:50 PM
newbie need ur help!! - by El Forum - 06-20-2010, 04:18 PM
newbie need ur help!! - by El Forum - 06-20-2010, 07:21 PM



Theme © iAndrew 2016 - Forum software by © MyBB