Welcome Guest, Not a member yet? Register   Sign In
pagination URI problem
#1

[eluser]iamsen47[/eluser]
This is my first time using CI, and probably the first time I've written my own PHP from scratch. I'm not a developer.
Using XAMPP, this page will load 20 results perfectly.

http://localhost/ci2/

When I click on next, it loads the next 20 results.

http://localhost/ci2/supporttest/index/20

However, from here onwards, the next/prev link just keeps adding [/supporttest/index/#] to the URL. I've been trying to fix this, for the past few hours and I still don't know what the problem is. Somebody help please.

http://localhost/ci2/supporttest/index/supporttest/index/40
http://localhost/ci2/supporttest/index/supporttest/index/supporttest/index/20

Code:
public function index
{
$this->load->library('pagination');
$config = array();
$config["base_url"] = "supporttest/index";
$config['total_rows'] = $data['num_results'];
$config['per_page'] = 20;
$config["uri_segment"] = 3;
$this->pagination->initialize($config);

$this->load->view('test/test', $data);
}

Only change I did to the route is switch welcome to my supporttest.php file.
Code:
$route['default_controller'] = 'supporttest';

This is the base URL I'm using in my config page. I've hidden index.php using .htaccess.
Code:
$config['base_url'] = 'http://localhost/ci2/';
#2

[eluser]NeoArc[/eluser]
I always load the url helper, because most of the time you need it for pagination, routing and stuff.

Code:
$config["base_url"] = base_url()."supporttest/index/"; //!!Trailing slash
#3

[eluser]Aken[/eluser]
To explain that answer - base URL should be either a full URL or an absolute URL, not a relative one like you had.

And use site_url() for links, not base_url().
#4

[eluser]iamsen47[/eluser]
Thanks Aken, your advise worked.




Theme © iAndrew 2016 - Forum software by © MyBB