CodeIgniter Forums
routing and pagination problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: routing and pagination problem (/showthread.php?tid=34202)



routing and pagination problem - El Forum - 09-22-2010

[eluser]LeonLanford[/eluser]
Hi, I'm new to codeigniter. I've read URI Routing manual and this thread. I have the same problem like that thread, I want to remove 'index' from the URI (http://localhost/igniter/hello/index/10) to (http://localhost/igniter/hello/10).

URI routing doesn't work for me so I use _remap function, but it made pagination doesn't works. If I press page 2, it keeps bold at page 1.

My question:
Is there something I need to do to activate the routing or fix the pagination when using _remap function?

I already tried to change
Code:
$config['uri_protocol']    = "AUTO";
QUERY_STRING and ORIG_PATH_INFO makes the page redirected to welcome page, others are just 404 not found error.

I also already change index_page to blank
Code:
$config['index_page'] = "";

htaccess code
Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Here's the controller code
Code:
<?php
class Hello extends Controller {

    function __construct()
    {
        parent::__construct();
        $this->load->helper('url');
        //$route['hello/:any'] = "hello/index/$1";
        //$route['hello/10'] = "hello/index/10";
        //$route['(:any)/'] = "hello";
    }
    
    public function _remap($strMethod='index')
    {
        call_user_func_array(array(&$this, 'index'), array_slice($this->uri->segment_array(), 2));
    }
    
    function index()
    {
        $this->output->enable_profiler(TRUE);
        
        $page_limit = 10;
        
        $segmen = $this->uri->segment(2,0);
        
        $this->load->model('hellomodel');
        $data['query'] = $this->hellomodel->get_entry("category", $segmen, $page_limit);
        
        $this->load->library('pagination');
        //$config['base_url'] = base_url().'hello/index/';
        $config['base_url'] = base_url().'hello/';
        $config['total_rows'] = $this->db->count_all('category');
        $config['per_page'] = $page_limit;
        $this->pagination->initialize($config);
        echo $this->pagination->create_links();
        
        $this->load->view('helloview', $data);
    }
}
?>

Thanks


routing and pagination problem - El Forum - 09-22-2010

[eluser]LeonLanford[/eluser]
I solved the pagination problem by looking at this thread.

I also already solved the routing, I put the route at config/routes.php.. Is there some way I can put the route in the controller?


routing and pagination problem - El Forum - 12-03-2010

[eluser]Cesar Kohl[/eluser]
I had the same problem. The solution is surprisingly simple:

Code:
$config['uri_segment'] = 2;

.. in the pagination config file I hope you created.