Welcome Guest, Not a member yet? Register   Sign In
Problem with offset in the url
#1

In the pagination when I change the number of the page with 0 or any other text give me an error of query, of course.

I could take it off with disable the debug mode in the database.php

But In tI would equally be a mistake not pleasant.

For this reason, in that way I can set an 404 error page when $offset it is different from a number and it is 0?

I can try with a simply if, but it does not work.

Thanks for the reply Smile
Reply
#2

The offset should be passed to the controller method for the paged content, so you should check the $offset value there before using it. Generally, I would cast the value to an int
Code:
$offset = (int) $offset;
then make sure the resulting value is in the valid range (between 1 and $num_pages, inclusive). The number of pages can be determined by the following code:
Code:
$num_pages = (int) ceil($total_rows / $per_page);
where $total_rows and $per_page are the values (of the same name) you pass to the pagination configuration (the code is, more or less, the same used by the pagination library to determine the total number of pages when you call create_links()).

If the value doesn't fall in that range, I usually default it to the closest valid value (1 or $num_pages), then redirect with the new $offset and display an error message that the requested page is not valid. If you want to display a 404 error, you can do that instead of redirecting.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB