Pagination problem, getting a blank page.

#1
[eluser]DustinH[/eluser]
I've been trying everything to get this pagination system to work, but everytime it comes up with a blank page, NOTHING is showing up and I've run outa options, can anyone see something that I cant?

Controller
Code:
<?php
session_start();
class Page extends Controller {

    function Page()
    {
        parent::Controller();
        
        $this->load->helper('url');
        $this->load->helper('form');
    }
    
    function index()
    {
    

    }
    
    function view()
    {
        $this->load->library('pagination');
           $this->load->model('Blog_model');
           $per_page = 10;
           $total = $this->posts_model->count_posts();
           $data['blogs'] = $this->posts_model->get_posts($per_page, $this->uri->segment(3));

           $base_url = site_url('page/view');
           $config['base_url'] = $base_url;
           $config['total_rows'] = $total;
           $config['per_page'] = $per_page;
           $config['uri_segment'] = '3';

           $this->pagination->initialize($config);
           $this->load->view('page_view', $data);
    
    }
    

}

?>

Model
Code:
<?php

class Blog_model extends Model {

function Blog_model()
{
  parent::Model();
}

function get_posts($limit = NULL, $offset = NULL)
{
  $this->db->limit($limit, $offset);
  return $this->db->get('Blogs');
}

function count_posts()
{
  return $this->db->count_all_results('Blogs');
}

}
?>


View
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
Blog Posts
<br />
&lt;?php
foreach ($blogs->results() as $blog):
echo $blog->Title, '
';
echo $blog->Body_content;
endforeach;

echo $this->pagination->create_links();
?&gt;

&lt;/body&gt;
&lt;/html&gt;

Any help would be greatly appreciated guys, I'm at my wits end.

#2
[eluser]pistolPete[/eluser]
The index() function is empty, does it work if you access domain.com/page/view ?

You should enable error reporting in index.php to see if you get any errors:
Code:
error_reporting(E_ALL);

You should also omit the closing tag: (user guide)
Quote:The PHP closing tag on a PHP document ?&gt; is optional to the PHP parser. However, if used, any whitespace following the closing tag, whether introduced by the developer, user, or an FTP application, can cause unwanted output, PHP errors, or if the latter are suppressed, blank pages. For this reason, all PHP files should OMIT the closing PHP tag, and instead use a comment block to mark the end of file and it's location relative to the application root. This allows you to still identify a file as being complete and not truncated.

#3
[eluser]DustinH[/eluser]
Hmmm, I seem to be getting an error with the Pagination Library...

Parse error: syntax error, unexpected '&' in /home/content/18/4876118/html/dev/system/libraries/Pagination.php on line 188

Fixed, for some reason my pagination library has some $gt; instead of > symbols. Weird.

#4
[eluser]DustinH[/eluser]
Now it's giving me some funky things, the 1 and the 2 link work fine, but 3 is linking to 4 and it says 4 is the max pages, but if I manually type in 5 I get more results.

Strange if I must say so.

#5
[eluser]Aken[/eluser]
In your model's count_posts() function, $this->db->count_all_results() is not a function. $this->db->count_all('Blogs'); would be the appropriate use.

Also not sure if it matters now, but in your controller you've called "Blog_model", but you're calling functions from "posts_model". Perhaps you've autoloaded it, or fixed it in your live version. But it looks out of place.

And on another random note, what's up with the session_start() up top?

#6
[eluser]DustinH[/eluser]
I had the session start there for some reason, I can't remember now. But I got things working good, the only problem it seems is that the Pagination doesn't increment by 1 but by 2. for example, Page 1 is the default view, page 2 is 2, page 3 is 4, page 4 is 6, page 5 is 8. Everything seems to comeout ok none the less. But I just found it akward that it would do that.

#7
[eluser]Aken[/eluser]
I don't know what you're experiencing, but maybe you're a bit confused on the way the Pagination class works. By default, the URL numbers generated are the beginning result count, with that number + results per page being the end result to return.

For instance, say you have a blog with XXX posts, and you want to show 10 per page. If you visited example.com/blog, you'd see 1-10. If you went to example.com/blog/10, you'd see 11-20 (or whatever exact number you set up). Example.com/blog/120 would show you 121-130, etc etc.

The class uses the beginning item count as a "page" number, instead of normal page numbers (eg. blog/page-3).


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.