what is this: $this ->

Discussion in 'PHP' started by gilgalbiblewheel, Jul 8, 2008.

  1. #1
    Can someone define what this is? What's happening here ?
    	//public function fetchPagedNavigation($queryVars = "") {
    	public function fetchPagedNavigation($queryVars) {
    		return $this->getLayout()->fetchPagedLinks($this, $queryVars);
    	}//end writeNavigation
    PHP:

     
    gilgalbiblewheel, Jul 8, 2008 IP
  2. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #2
    It's running the internal class method getLayout()
    which then has a line:
    return $this;

    allowing method chaining (PHP 5 only)
    which then runs fetchPagedLinks - passing $this and the original $queryVars as a second variable.

    (Lots of carriage returns, hopefully it will make it easier to understand - try Googling 'method chaining'.
     
    Danltn, Jul 8, 2008 IP
  3. gilgalbiblewheel

    gilgalbiblewheel Well-Known Member

    Messages:
    435
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #3
    I'm trying to insert making $queryVars equal to this for-loop.
    $queryVars = "";
    //for the url
    	for ($j=0; $j < count($newSearchTheseArr); $j++){
    		if($j!= count($newSearchTheseArr)-1){
    			$queryVars .= $newSearchTheseArr[$j]."+";
    		}else{
    			$queryVars .= $newSearchTheseArr[$j];
    		}
    	}
    	//echo "hi".$queryVars."hi<br />";
    PHP:
    in this:
    //public function fetchPagedNavigation($queryVars = "") {
    public function fetchPagedNavigation($queryVars) {
    	return $this->getLayout()->fetchPagedLinks($this, $queryVars);
    }//end writeNavigation
    PHP:
     
    gilgalbiblewheel, Jul 8, 2008 IP
  4. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #4
    You'll need to post the whole class and any parent classes.

    Btw, what's wrong with www.php.net/urlencode? Sounds like what you need.

    Dan
     
    Danltn, Jul 8, 2008 IP
  5. gilgalbiblewheel

    gilgalbiblewheel Well-Known Member

    Messages:
    435
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #5
    There were a few files downloaded since it was a tutorial.
    class Paginated {
    
    	private $rs;                  			//result set
    	private $pageSize;                      //number of records to display
    	private $pageNumber;                    //the page to be displayed
    	private $rowNumber;                     //the current row of data which must be less than the pageSize in keeping with the specified size
    	private $offSet;
    	private $layout;
    
    	function __construct($obj, $displayRows = 10, $pageNum = 1) {
    		$this->setRs($obj);
    		$this->setPageSize($displayRows);
    		$this->assignPageNumber($pageNum);
    		$this->setRowNumber(0);
    		$this->setOffSet(($this->getPageNumber() - 1) * ($this->getPageSize()));
    	}
    
    	//implement getters and setters
    	public function setOffSet($offSet) {
    		$this->offSet = $offSet;
    	}
    
    	public function getOffSet() {
    		return $this->offSet;
    	}
    
    
    	public function getRs() {
    		return $this->rs;
    	}
    
    	public function setRs($obj) {
    		$this->rs = $obj;
    	}
    
    	public function getPageSize() {
    		return $this->pageSize;
    	}
    
    	public function setPageSize($pages) {
    		$this->pageSize = $pages;
    	}
    
    	//accessor and mutator for page numbers
    	public function getPageNumber() {
    		return $this->pageNumber;
    	}
    
    	public function setPageNumber($number) {
    		$this->pageNumber = $number;
    	}
    
    	//fetches the row number
    	public function getRowNumber() {
    		return $this->rowNumber;
    	}
    
    	public function setRowNumber($number) {
    		$this->rowNumber = $number;
    	}
    
    	public function fetchNumberPages() {
    		if (!$this->getRs()) {
    			return false;
    		}
    		
    		$pages = ceil(count($this->getRs()) / (float)$this->getPageSize());
    		return $pages;
    	}
    
    	//sets the current page being viewed to the value of the parameter
    	public function assignPageNumber($page) {
    		if(($page <= 0) || ($page > $this->fetchNumberPages()) || ($page == "")) {
    			$this->setPageNumber(1);
    		}
    		else {
    			$this->setPageNumber($page);
    		}
    		//upon assigning the current page, move the cursor in the result set to (page number minus one) multiply by the page size
    		//example  (2 - 1) * 10
    	}
    
    	public function fetchPagedRow() {
    		if((!$this->getRs()) || ($this->getRowNumber() >= $this->getPageSize())) {
    			return false;
    		}
    
    		$this->setRowNumber($this->getRowNumber() + 1);
    		$index = $this->getOffSet();
    		$this->setOffSet($this->getOffSet() + 1);
    		return $this->rs[$index];
    	}
    
    	public function isFirstPage() {
    		return ($this->getPageNumber() <= 1);
    	}
    
    	public function isLastPage() {
    		return ($this->getPageNumber() >= $this->fetchNumberPages());
    	}
    
    	/**
    	 * <description>
    	 * @return PageLayout <description>
    	 */
    	public function getLayout() {
    		return $this->layout;
    	}
    
    	/**
    	 * <description>
    	 * @param PageLayout <description>
    	 */
    	public function setLayout(PageLayout $layout) {
    		$this->layout = $layout;
    	}
    
    	//returns a string with the base navigation for the page
    	//if queryVars are to be added then the first parameter should be preceeded by a ampersand
    
    
    	//public function fetchPagedNavigation($queryVars = "") {
    	public function fetchPagedNavigation($queryVars) {
    		return $this->getLayout()->fetchPagedLinks($this, $queryVars);
    	}//end writeNavigation
    }//end Paginated
    PHP:
     
    gilgalbiblewheel, Jul 8, 2008 IP