Welcome Guest, Not a member yet? Register   Sign In
404 errors when using pagination. SOLVED!!!
#1

[eluser]jjmax[/eluser]
Hi,

I just spent an hour or so trying to figure out why I was getting 404 errors when using the pagination class.

I figured it out myself after a while and it all had to do with adding a line to my routes file.

Here's the code I was using and the line I added to the routes file.

Controller
Code:
public function index($page='0')
{
  $this->load->model('frontend_model');
  $this->load->library('pagination');
  
  $content['headline'] = 'Catalogue';
  $content['maincontent'] = 'the site gallery goes here with pictures of the models linking to their profile pages';
  $active['meta_title'] = "Eros - The web's premium erotic models";
  $active['meta_description'] = "Eros is the number one website for finding erotic models in Australia";
  $active['catalogueactive'] = 1;
  
  
  $config['base_url'] = base_url() . 'catalogue/';
  $config['total_rows'] = $this->db->count_all('model');
  $config['per_page'] = '12';

  $this->pagination->initialize($config);
  
  $content['models'] = $this->frontend_model->get_models($config['per_page'],$page);
  
  $this->load->view('template/gallery-header', $active);
  $this->load->view('frontend/catalogue', $content);
  $this->load->view('template/footer');
}

Model
Code:
public function get_models($num, $offset)
{
  $q = $this
    ->db
    ->select('id, name, location, profilepic, active, createdate')
    ->order_by('createdate', 'desc')
    ->where('active', '1')
    ->get('model', $num, $offset);
  
  $data = NULL;
  
  foreach($q->result_array() as $row){
   $data[] = array(
    'image' => $row['profilepic'],
    'name' => $row['name'],
    'location' => $row['location'],
    'id' => $row['id']
    );
  
  }
    
  return $data;
}
View
Code:
<div id="gallery">
      &lt;?php if (isset($models))
      {
       foreach ($models as $model)
       {
        echo '<a class="gallery" href="' . base_url() . 'catalogue/model/' . $model['id'] . '"><img class="corners iradius12" src="' . base_url() . 'gallery/thumbs/' . $model['image'] . '" title="' . $model['name'] . '" /></a>';
       }
      }
      ?&gt;
      <p>&lt;?php echo $this->pagination->create_links(); ?&gt;</p>
     </div>
Routes file(at end, last entry in Reserved Routes section)
Code:
$route['^(catalogue)(/:any)?$'] = "catalogue/$0";

I hope this helps someone else. I couldn't find anything when I looked but this solution just kind of dawned on me after a while Smile

John




Theme © iAndrew 2016 - Forum software by © MyBB