0

I have a view with pager. The views pager is not AJAX and the pager id comes is the URL as http://d7.local?page=3 There are total of 15 pages in the view. So the last page is http://d7.local?page=14 Now if I manually enter a pager number which is higher that 14 say 30 it redirects to the last page Need to redirect the user to a 404 page under this situation.

  • It doesn't 'redirect' to the last page - the calculation of current_page_num * num_per_page is the upper limit of the range in the query, so 14 * 10 = 140: SELECT * FROM foo LIMIT 10, 140. Similarly 30 * 10 = 300: SELECT * FROM foo LIMIT 10, 300, which for a table with <= 140 records will produce the same resultset. What you're looking at is by design, I'm not sure there's an easy way to get around it – Clive Sep 10 '14 at 9:49
  • But in my case its showing the results from the last page. I guess normally it should show a blank page. – Malabya Tewari Sep 10 '14 at 10:01
  • Yep, that's exactly the point I was making. It's supposed to show the results from the last page (see the above comment for the full explanation). What you're seeing is the expected behaviour of the module – Clive Sep 10 '14 at 10:09
  • Ohkk.. any idea how to overrode this behavior? – Malabya Tewari Sep 10 '14 at 10:14
0

Found a way out!!.. I used theme_pager and global variable $pager_total

Here is the code

/**
 * Implements theme_pager
 */
function theme_pager($variables) {
  global $pager_total;
  if ($_GET['page'] > $pager_total[0]) {
    drupal_not_found();
    exit;
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.