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

[eluser]r@mtbb_[/eluser]
Hi,

I'm sorry to bother you with a very discussed topic but, I still can't make pagination to work on my website. Here's the code:
Code:
//controller
function index()
    {
    $config['base_url'] = 'http://localhost/website/index.php/see/';
    $config['total_rows'] = $this->db->count_all('projects');
    $config['per_page'] = 4;
    $config['uri_segment'] = 2;
    $this->pagination->initialize($config);
    
    $num     = $config['per_page'];
    $offset = $this->uri->segment(2);
    
    $this->db->orderby("date","desc");
    $data['query']= $this->db->get('projects', $num, $offset);

    $data['links']=$this->pagination->create_links();
    $this->load->view('see_view',$data);
    }
Code:
//view_file
<?php foreach($query->result() as $row): ?>
<h3>&lt;?php echo $row->title; ?&gt;</h3>
<p>&lt;?php echo $row->description; ?&gt;</p>

<hr />
&lt;?php endforeach; ?&gt;
&lt;?php echo $links; ?&gt;
When i load index.php/see , I get the correct 4 results per page, the correct numbers of links considering the total rows, but when I click a link, there's a 404 message.
The links don't have correct paths. They change along with the $config['per_page']. All the necessary libraryes and helpers are loaded. What could be the problem?
Thanks!
#2

[eluser]Craig A Rodway[/eluser]
What difference does it make if you change the base_url variable to site_url('see/index'); ?
#3

[eluser]Mark van der Walle[/eluser]
Indeed, CI will create the following urls:
http://localhost/website/index.php/see/0
http://localhost/website/index.php/see/4
http://localhost/website/index.php/see/8

When you click on that it will try to call a controller see with the function 0,4,8 etc. These dont exist (and could not for that matter). Either use some URI routing if you do not want to show the index or add the index to the baseurl
#4

[eluser]r@mtbb_[/eluser]
Thanks for the help! If I change the base_url variable with site_url(’see/index’), I won't get a 404 but the page won't change neither. How can I create URI routing to solve this?

UPDATE:
Nevermind. It works now with site_url(’see/index’) and the URI segment is 3.
Thank you! Smile




Theme © iAndrew 2016 - Forum software by © MyBB