CodeIgniter Paging 404

和自甴很熟 提交于 2019-12-06 22:34:32

$route['admin/(:num)'] = 'admin/index/$1'; needs to reside in config/routes.php- you cannot add routes to controller methods.

OK, I've figured out what is going on.

When accessing a paged result other than the first page I was at the URI 'localhost/cream/public_html/admin/$1', where $1 represents the page number.

In my 'Admin' controller code, under the index() function, the '$config['uri_segment']' property value needed to be set to 2. This alone wouldn't have fixed the issue but it was the correct URI segment.

Next, I needed to add the following 2 routes to 'routes.php':

$route['admin'] = 'admin/admin';
$route['admin/:num'] = 'admin/admin';

The first route was because I had now changed my controller class name to 'Admin' and its filename to 'admin.php', so I needed a route that would work when the user was at the following URI:

localhost/cream/public_html/admin/

The second route was to reroute the page number to the correct controller, which was now 'admin/admin'.

That was it. My pagination is now working.

All I need to do now is get it to change the '$limit' variable so that it can be dynamically changed via a drop down. I should be able to pass the value of the dropdown to $_POST and pull it in to my 'get_paged_events();' function in my model. I'll let you know how I get on.

Cheers for all the help folks.

To avoid index from your paging just follow the below step

Step1: customize /config/routes.php

   $route['controller/(:num)'] = "controller/index/$1";
   It convert your url www.yourdomian.com/controller/(number) to www.yourdomain.com/controller/index/(number)

Step2: Customize your pagination code with $config['uri_segment'] = 2 like below

        $config['base_url'] = base_url().'controller/';
        $config['display_pages'] = TRUE;
        $config['first_link'] = 'First';
        $config['total_rows'] = (your total rows);
        $config['uri_segment'] = 2;
        $this->pagination->initialize($config);
        echo $this->pagination->create_links();

cheers..

Do you have url rewriting on your web server? If don't then try localhost/path/to/codeigniter/index.php/admin. If you want to skip the index.php then read about mod_rewrite (if you are using apache) and check the codeigniter's user guide for site_url function that might be useful to generate in-site urls.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!