Welcome Guest, Not a member yet? Register   Sign In
pagination from index function?
#1

[eluser]Corey Freeman[/eluser]
sorry to bother everyone again. I'm using the Ajax Pagination library and I can't manage to paginate results from the controller's index (which would make the interface look so much cleaner...). Any help would be awesome.

Code:
<?php
class Dashboard extends Controller {
    function dashboard() {
        parent::Controller();
        $this->load->library('Jquery_pagination');
        if ($this->session->userdata('is_logged_in') != TRUE)
        {
            redirect('login');
        }
    }
    function index() {
        $data['title'] = 'Your ReveCloud Dashboard';
        $this->db->where('id', $this->session->userdata('id'));
        $data['user'] = $this->db->get('users');
        ///////////////////////////////////////////////////////////
            $id = $this->session->userdata('id');
            $this->db->where('user_id', $id);
            $this->db->where('complete', 0);
            $this->load->model('goal_model');
            $total = $this->goal_model->count_goals();
            $per_page = 5;
            $config['base_url'] = site_url('dashboard');
            $config['total_rows'] = $total;
            $config['per_page'] = 5;
            $config['div'] = 'body';
            $config['uri_segment'] = '1';
            $this->jquery_pagination->initialize($config);
            $this->db->where('user_id', $id);
            $this->db->where('complete', 0);
            $data['dreams'] = $this->goal_model->get_goals($per_page, $this->uri->segment(1));
        ///////////////////////////////////////////////////////////
        $this->db->where('complete', 1);
        $this->db->where('user_id', $this->session->userdata('id'));
        $data['complete'] = $this->db->get('goals');
        $this->load->view('dashboard', $data);
    }
#2

[eluser]mddd[/eluser]
If a user calls /dashboard/2 the system will look for a method called '2' in the Dashboard controller. That's not working.
You have some options:
- use urls like /dashboard/index/2
- add a _remap function in the controller to always call index(): function _remap() { $this->index(); } or even simpler, rename your index() method _remap()
- add a route to your config/routes.php to rewrite the url: $route['dashboard/(:num)'] = 'dashboard/index/$1';
#3

[eluser]Corey Freeman[/eluser]
You totally rock! The routes thing worked fantastically. Smile
#4

[eluser]mddd[/eluser]
No problem Smile




Theme © iAndrew 2016 - Forum software by © MyBB