2013-05-16 3 views
0

PHP 간단한 페이지 매김 클래스를 작성하고 싶습니다. 여기 내 코드는 다음과 같습니다.PHP 클래스 변수를 에코 할 수 없습니다

<?php 
class Pagination { 
public $rowsPerPage; 
public $currentPage; 
public $totalPages; 
public $totalRows; 
public $firstElement; 
public $lastElement; 


    public function paginate() 
     { 
      if(isset($_GET['page'])){ 
       $this->currentPage = $_GET['page'];  
      }   

         $this->totalPages = $this->totalRows/$this->rowsPerPage ; 
      return $this->totalPages; 

       $this->firstElement = $this->currentPage-1)*$this->rowsPerPage+1; 
       return $this->firstElement;     
     } 
} 

$totalRecords = 55; 
$paginator = new Pagination(); 
$paginator->totalRows = $totalRecords; 
$paginator->rowsPerPage = 5; 
$paginator->paginate(); 
echo $paginator->totalPages; 
echo $paginator->firstElement; 
?> 

echo $ paginator-> totalPages; 하지만 $ paginator-> firstElement는 아닙니다. 내가 뭘 잘못 했니? 감사합니다.

+0

I가도 _construct 기능 공개 _construct 함수() { \t \t \t $ this-> rowsPerPage = 5; $ this-> currentPage = 1; $ this-> totalPages = 0; \t \t \t $ this-> totalRows = 40; \t \t \t $ this-> firstElement = 0; \t \t \t $ this-> lastElement = 0; \t \t \t – user2359958

+4

$ this-> firstElement에 구문 오류가 있지만 닫는 괄호는 있지만 여는 것은 아닙니다. –

+0

[오류보고]를 켜십시오 (http://php.net/error+reporting). –

답변

8

paginate 함수에 두 개의 return 문이 있습니다.

코드가 return $this->totalPages;에 도달하면 기능 실행이 중지됩니다. 따라서 $this->firstElement = ... 행은 실행되지 않습니다.

+2

나를 이길! –

+2

@ChrisB : 저는 닌자입니다 ^^ –

+0

와우 .. 고마워 :))) – user2359958

관련 문제