Welcome Guest, Not a member yet? Register   Sign In
Pagination Problem
#1

[eluser]Unknown[/eluser]
Hello to all

I'm having a problem with the library 'Pagination'. All ties come in a 404 error (page not found).
Mereover, if I change my
Code:
$config['base_url'] = base_url().'admin/article/';
by
Code:
$config['base_url'] = base_url().'admin/article/index';
the links work .

However, I have another problem. The pagination links are on page 1 when you click on page 2 for example.

So I changed the
Code:
$config['uri_segment'] = '3';
by
Code:
$config['uri_segment'] = '4';
and then everything works fine.

I would like to know why do I make these changes so that it works.

The hierarchy of my application:

application/

----controllers/

--------admin/

------------admin.php
------------article.php

----models/

------------articles.php

----views/

--------admin/

------------content/

----------------admin.php
----------------article.php

------------includes/

----------------footer.php
----------------header.php
----------------template.php


My config's file for routes -> route.php

// application/config/routes.php
$route['admin'] = "admin/admin";
$route['admin/article'] = "admin/article";




My Controller article.php
<?PHP
class Article extends Controller {

function __construct() {
parent::Controller();
}

function index(){
$this->load->library('pagination');
$this->load->model('articles');


$config['base_url'] = base_url().'admin/article/index/';
$config['total_rows'] = $this->articles->getNumArticles();
$config['per_page'] = '2';
$config['uri_segment'] = '3';
$config['num_links'] = '4';
$this->pagination->initialize($config);

$tpl['articles'] = $this->articles->getArticles($config['per_page'], $this->uri->segment(3));
$tpl['file'] = "article";

$this->load->view('admin/includes/template',$tpl);

}
}
/* End of file article.php */
/* Location: ./system/application/controllers/admin/article.php */


I hope you understand my problem

Sorry for my English, I'm French ;-)


Pierre
#2

[eluser]Jeremy Gimbel - Conflux Group[/eluser]
I imagine what's happening here is that when you click a pagination link it's adding a third parameter to your URL, which CI automatically assumes is the method, because of the routing structure. To make it work without having the index method in the URL, you might try adding a custom route to your config/routes.php file, like this:

Code:
$route['admin/article/(:num)'] = "admin/article/index/$1";
#3

[eluser]Unknown[/eluser]
Thank you very much.

Everything works perfectly now

Pierre




Theme © iAndrew 2016 - Forum software by © MyBB