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

[eluser]clintonbeattie[/eluser]
Hi,

Pagination doesn't work. Have read a few tutorials and I think this code should be okay...
The initial page shows all the results from teh database but still shows the pagination. When I click on "2" in the pagination it brings up..


Code:
404 Page Not Found

The page you requested was not found.


Controller
Code:
function index()
    {
        $data['page_title'] = "Join Tables";
        $data['description'] = "Blog";
        $data['keywords'] = "Blog";
        
        
        

        $config['base_url'] = base_url();
        $config['total_rows'] = $this->db->count_all('posts');
        $config['per_page']= 2;
        $config['full_tag_open'] = '<p>';
        $config['full_tag_close'] = '</p>';
        $this->pagination->initialize($config);
        $data['paging_links'] = $this->pagination->create_links();
        
         //load the model and get results

        $data['blogposts'] = $this->MBlog->getAllPosts($config['per_page'],$this->uri->segment(3));
        
        $data['main'] = 'blog';
        $this->load->vars($data);
        $this->load->view('template');
    }

View
Code:
&lt;?php
foreach ($blogposts as $key => $post){
    echo "<h4>".$post['post_title']."</h4>";
    echo "<p>".date('d M Y', strtotime($post['post_date'])) ."</p>";
    echo "<p>".$post['post_intro']."</p>";
    
    echo anchor('welcome/post/'.$post['id'],'Read More');

}
?&gt;

&lt;?php echo $this->pagination->create_links(); ?&gt;
#2

[eluser]pistolPete[/eluser]
Quote: base_url
This is the full URL to the controller class/function containing your pagination.
You should add the controller to the base_url setting.

Which links are generated? How should they look like?

Btw: You generate the links twice:

Code:
// controller
$data['paging_links'] = $this->pagination->create_links();

// view
&lt;?php echo $this->pagination->create_links(); ?&gt;
#3

[eluser]clintonbeattie[/eluser]
Hi,

I've updated some of the code but it still doesn't work...
This is my base_url "http://localhost/blog/"

The view should now use $pagination_links but same thing is happening.

This is teh url when I click on link "2" in the pagination, "http://localhost/blog/2" . 404 is shown.

Controller
Code:
function index()
    {
        $data['page_title'] = "Join Tables";
        $data['description'] = "Blog";
        $data['keywords'] = "Blog";
        
        
        

        $config['base_url'] ='http://localhost/blog/';
        $config['total_rows'] = $this->db->count_all('posts');
        $config['per_page']= 2;
        $config['full_tag_open'] = '<p>';
        $config['full_tag_close'] = '</p>';
        $this->pagination->initialize($config);
        $data['paging_links'] = $this->pagination->create_links();
        
         //load the model and get results

        $data['blogposts'] = $this->MBlog->getAllPosts($config['per_page'],$this->uri->segment(3));
        
        $data['main'] = 'blog';
        $this->load->vars($data);
        $this->load->view('template');
    }

View
Code:
&lt;?php
foreach ($blogposts as $post){
    echo "<h4>".$post['post_title']."</h4>";
    echo "<p>".date('d M Y', strtotime($post['post_date'])) ."</p>";
    echo "<p>".$post['post_intro']."</p>";
    
    echo anchor('welcome/post/'.$post['id'],'Read More');

}
?&gt;
&lt;?php echo $paging_links; ?&gt;
#4

[eluser]pistolPete[/eluser]
Use this:
Code:
function index($page)
    {
       ...
        $config['base_url'] ='http://localhost/blog/index/';
       ...
         //load the model and get results

        $data['blogposts'] = $this->MBlog->getAllPosts($config['per_page'],$page);
...
#5

[eluser]clintonbeattie[/eluser]
Mmmm. Doesn't work.

"Undefined variable: page"
#6

[eluser]pistolPete[/eluser]
This should do it:
Code:
function index($page = 0)
#7

[eluser]clintonbeattie[/eluser]
Nope. Soooo frustrating.

I have this "$config['per_page']= 1;" but the initial page doesn't limit the results. For example, I have 3 posts in my database. The page displays all 3 but also displays the pagination. Very odd indeed.

Thanks for the help so far.
#8

[eluser]w0bbes[/eluser]
[quote author="modelreject" date="1237760719"]Nope. Soooo frustrating.

I have this "$config['per_page']= 1;" but the initial page doesn't limit the results. For example, I have 3 posts in my database. The page displays all 3 but also displays the pagination. Very odd indeed.

Thanks for the help so far.[/quote]

Im having problems also. The pagination is displaying although it just displays all the pictures. It prolly has something to do with my view file.

Controller:
Code:
$data['aantal'] = count($data['fotos']->result());
                
                

                $config['base_url'] = site_url().'foto/cat/'. $this->uri->segment(3) .'/'. $this->uri->segment(4);
                $config['total_rows'] = $data['aantal'];
                $config['per_page'] = '4';
                $config['uri_segment'] = '5';
                

                $this->pagination->initialize($config);

                if($data['aantal'] > $config['per_page']){
                    $this->pagination->create_links();
                }
                

                $this->load->view('fotos',$data);

This is my view file:
Code:
<table class="album">
    <tr><td colspan="4">Er zijn &lt;?=$aantal?&gt; fotos gevonden.</td></tr>
        &lt;?
        $i = '0';
        foreach($fotos->result() as $txt){
            if($i == '0'){
                echo '<tr><td><img >uri->segment(4)) . '/thumb_' . $txt->naam . '"></td>';
                $i++;
            }elseif($i == '3'){
                echo '<td><img >uri->segment(4)) . '/thumb_' . $txt->naam . '"></td></tr>';
                $i = '0';
            }else{
                echo '<td><img >uri->segment(4)) . '/thumb_' . $txt->naam . '"></td>';
                $i++;
            }
        }
        ?&gt;
        <tr><td colspan="4">&lt;?=$this->pagination->create_links()?&gt;</td></tr>
    </table>



Any help would be appreciated




Theme © iAndrew 2016 - Forum software by © MyBB