TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 04-17-2009, 09:20 PM   #1 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default Help with class....

Ok, I am working on a pagination class, I figured I will break up the "methods" and figure them out one at a time instead of trying to write a class with 10+ methods...so I am going to do one at a time, make sure I get the results, and eventually combine everything together.

But I am having a problem already, I keep getting a blank page.



Here's my class file.

Code:
<?

class pagination {

/* GENERATE LINKS ex: 1 2 3 4 5 6 7 8 */
public function getPageLinks(int $page_last,int $get_page) {

$this->pageLast = $page_last;
$this->getPage = $get_page;
	
for ($i=1; $i<=$this->pageLast; $i++) { 

if(($this->getPage - 2) == $i) $display_pages[] = " <a href=\"$_SERVER[PHP_SELF]?p=$i\">$i</a>";
if(($this->getPage - 1) == $i) $display_pages[] = " <a href=\"$_SERVER[PHP_SELF]?p=$i\">$i</a>";
if($this->getPage == $i) $display_pages[] = "$i";
if(($this->getPage + 1) == $i) $display_pages[] = " <a href=\"$_SERVER[PHP_SELF]?p=$i\">$i</a>";
if(($this->getPage + 2) == $i) $display_pages[] = " <a href=\"$_SERVER[PHP_SELF]?p=$i\">$i</a>";

	}
		
return $this->displayPages = $display_pages;
			
}
		
		

}###END CLASS
	
?>

Here's my HTML.

Code:
<?

include_once("pagination.php");

/* LETS SET SOME VARIABLES TO SIMULATE USER EXPERIENCE */
$page_limit = 25;
$get_page = 7;
	
/* ARRAY WILL SIMULATE DATABASE ENTRIES */
$array = array(1,2,3,4,5,6,7,8,9,10);
$totalrows = count($array);
$page_last = 10;

/* CREATE OBJECT */
$pagination = new pagination();

$display_links = $pagination->getPageLinks(int $page_last,int $get_page);
	
echo "implode(' ',$display_links)";

?>


Since the current page is set to 7. I am giving it the last page which is 10, and the current page 7.


So anyways, the output should be: 5 6 7 8 9

But instead it's just blank??
allworknoplay is offline  
Reply With Quote
Old 04-17-2009, 09:34 PM   #2 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Sorry, it's not blank, I was looking at the wrong browser.

I'm getting a parse error...


Parse error: syntax error, unexpected T_VARIABLE in /usr/local/apache/public/paginate.html on line 17
allworknoplay is offline  
Reply With Quote
Old 04-17-2009, 10:13 PM   #3 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Ok I got it working but I had to remove the INT from the function calls.

So in the HTML, I had to do this:

$display_links = $pagination->getPageLinks($page_last,$get_page);

Instead of:

$display_links = $pagination->getPageLinks(int $page_last, int $get_page);


And in the class, I had to use this:

public function getPageLinks($page_last, $get_page) {


Instead of this:

public function getPageLinks(int $page_last,int $get_page) {


But I don't understand, I thought it was proper coding to type hint the attributes?
allworknoplay is offline  
Reply With Quote
Old 04-17-2009, 10:23 PM   #4 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Quote:
Originally Posted by PHP_Manual
Type Hints can only be of the object and array (since PHP 5.1) type. Traditional type hinting with int and string isn't supported.
Plus, you wouldn't want to be type hinting when calling a method anyway. Only in the function/method declaration. Using it the way that you did, the argument would need to have belonged to a class/interface called 'int'.
Salathe is offline  
Reply With Quote
Old 04-17-2009, 10:26 PM   #5 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by Salathe View Post
Plus, you wouldn't want to be type hinting when calling a method anyway. Only in the function/method declaration. Using it the way that you did, the argument would need to have belonged to a class/interface called 'int'.
thanks Salathe...I "think" I understand...
allworknoplay is offline  
Reply With Quote
Old 04-18-2009, 12:41 PM   #6 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

One thing to keep in mind though, is that every classvariable ($this->classvariable) should be declared in the beginning of the class.

Like such:
PHP Code:
class Pagination {

private 
$classvariable1;
private 
$classvariable2;
private 
$classvariable3;

// in your methods you can then access them like normal: $this->classvariable1 or 2 or 3 respectivly.


Note that you can use whichever scope you want right now, but I would strongly advice you not to use public classvariables.

Also note that it will work even if you don't declare them, however the PHP will work faster if you declare them, so just an advice.
__________________
Tanax is offline  
Reply With Quote
Old 04-18-2009, 02:03 PM   #7 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by Tanax View Post
One thing to keep in mind though, is that every classvariable ($this->classvariable) should be declared in the beginning of the class.

Like such:
PHP Code:
class Pagination {

private 
$classvariable1;
private 
$classvariable2;
private 
$classvariable3;

// in your methods you can then access them like normal: $this->classvariable1 or 2 or 3 respectivly.


Note that you can use whichever scope you want right now, but I would strongly advice you not to use public classvariables.

Also note that it will work even if you don't declare them, however the PHP will work faster if you declare them, so just an advice.
Yes I am declaring all my properties to "private". I hope I can show you my class later today, it is almost done.

I think writing a pagination class script is a good way to learn OO. Much better than doing a "hello world" in OO....
allworknoplay is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Tutorial] How to organize your classes | Part 1 Tanax Advanced PHP Programming 10 03-01-2009 10:08 PM
A Generic Singleton Base Class Theo Advanced PHP Programming 7 08-18-2008 02:25 AM
[Tutorial] Basic tutorial about class basics Tanax Absolute Beginners 14 07-24-2008 01:37 PM
PHP5 Classes A to Z Part 1 quantumkangaroo Advanced PHP Programming 11 04-01-2008 04:21 AM
Tutorial: PHP and OOP, a beginners guide Village Idiot Tips & Tricks 0 09-06-2007 04:23 PM


All times are GMT. The time now is 10:54 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design