Welcome Guest, Not a member yet? Register   Sign In
Please help: Questions about: Dynamic Routing, Dynamic Pages, Dynamic Navigation
#2

[eluser]CtheB[/eluser]
Now we can make a module called pages, here is the controller:
Code:
<?php

class Pages extends Controller {
    
    public function __construct()
    {
        parent::Controller();
        $this->load->model('pages_model');
        $this->load->library('pagination');
    }

    public function index()
    {
            if ( $page = $this->pages_model->get_page($this->pagination->menuId) )
            {
                $view['pages'] = $page;
                $this->load->view('index', $view);
            }
            else
            {
                $this->output->set_header("HTTP/1.0 404 Not Found");
                $this->load->view('404');

            }
        }

}
/* End of file pages.php */
/* Location: ./application/modules/pages/controllers/pages.php */

And here is the model:
Code:
<?php

    class Pages_Model extends Model {
        
        protected $table;
        protected $menu;
        
        public function __construct()
        {
            parent::Model();
            $this->table = 'pages';
            $this->menu = 'navigations';
        }

        public function get_page($id)
        {
            $this->db->join($this->menu, $this->table . '.id =' . $this->menu . '.pages_id ', 'left')->where($this->menu . '.id', $id);
            $query = $this->db->get($this->table, 1);

            if ( $query->num_rows() == 1 )
            {
                return $query->row_array();
            }
            else
            {
                return false;
            }
        }
    }
/* End of file pages_model.php */
/* Location: ./application/modules/pages/models/pages_model.php */

In the view now, i can echo the title of the current page: $pages['title'];
etc etc.

The Help I need
Is this the correct way for doing this? I think things can be smarter, better..
What about the routing? Is there a way arround my current methode?
What about the library? Is there another way getting the id of the current page?

Please help me!
My thanks will be great!


Carlos


Messages In This Thread
Please help: Questions about: Dynamic Routing, Dynamic Pages, Dynamic Navigation - by El Forum - 01-29-2009, 08:36 AM



Theme © iAndrew 2016 - Forum software by © MyBB