Solved

$_GET inside a PHP class

Posted on 2010-11-29
3
654 Views
Last Modified: 2012-05-10
I have a theoretical question about a class construction in PHP.

Let's say i want to build a pagination class and i want to handle user input inside the class
(buttons - Next, Prev). I imagine i would have to call the script again $PHP_SELF when pressing
next or Prev button, and then through $_GET display the required set of records, so can I
construct my script like this example:

 <html>
  ..  header etc.

 <?php
 require_once   'paginate.php';
   mypagination = new Page;  

   PAge->display();


 ?>

I mean, is it a common approach ?. Would it matter that new Page, would be executed each
time user clicks Next, Prev buttons ?
0
Comment
Question by:iskibinska
3 Comments
 
LVL 17

Assisted Solution

by:sweetfa2
sweetfa2 earned 100 total points
ID: 34235417
A lot of pages use a similiar option to this.

A lot of pages will refresh on a list change.

The other approach is to use ajax style processing to load prev/next in the background but requires more work at the client side in particular.
0
 

Accepted Solution

by:
ilnnlm earned 150 total points
ID: 34238158
You can create the "Page" object once and store it in a session variable. Like this you will have the current page stored in the object and you can call methods like "Page->Next()", "Page->Previous()" or "Page->GoTo()".

To store the object in a session variable you will need to use the functions "serialize()" & "unserialize()" refer to the manual here http://php.net/manual/en/function.serialize.php
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 34239386
There is a canonical and definitive description of pagination here (feel free to ignore the popups, although they advertise good books):
http://articles.sitepoint.com/article/perfect-php-pagination

$_GET is one of the superglobals, so it is present in all namespaces and variable scopes.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question