如何按功能访问另一个页面中的私有变量?

时间:2014-01-12 09:42:37

标签: php

randomClass.php

class randomClass
{

    private $perPage = 8;
    private $startPage = 0;

    function perPage($perPage)
    {
        $this->db->perPage = $perPage;
    }

    function startPage($startPage)
    {
        $this->db->startPage = $startPage;
    }

    public function usingBothVariables()
    {
        $sth = $this->db->prepare("SELECT rndm FROM table LIMIT ?, ?");
        $sth->execute(array($this->startPage, $this->PerPage));

        $row = $sth->fetchAll();
        return $row;
    }
{

index.php

if($randomVariable < 1)
   use startPage function here = 0;
else 
   use startPage function here = $randomVariable * use $perPage function here;

1 个答案:

答案 0 :(得分:1)

在randomClass中:

public function getPerPage(){ 
  return $this->perPage;
}
public function getStartPage(){ 
  return $this->startPage;
}

现在在index.php中,您可以调用这些方法来获取yuor变量。