php 在类里定义了方法为什么创建对象后调用方法说没有定义 10
这是page.class.php<?phpclassPage{private$total;//总条数private$pages;//总页数private$tal;//每页...
这是page.class.php
<?php
class Page{
private $total; //总条数
private $pages; //总页数
private $tal; //每页的条数
private $url;
private $cpage; //当前页
function __construct($total,$tal){
$this->total = $total;
$this->tal = $tal;
$this->pages = $this->gettal();
$this->url="page1.php";
$this->cpage=!empty($_GET['page']) ? $_GET['page']:1;
}
function gettal(){
return ceil($this->total / $this->tal);
}
function first(){
$pre =$this->cpage-1;
if($this->cpage>1){
return '<a href="'.$this->url.'?page=1">首页</a> <a href="'.$this->url.'?page='.$pre.'">上一页</a>';
}
else return "";
}
function clist(){
$sum=4;
$list="";
for($i=$sum;$i>=1;$i--){
$page = $this->cpage-$i;
if($page>0)
$list.= ' <a href = "'.$this->url.'?page='.$page.'">'.$page.' </a>';
}
if($this->pages>1)
$list.= ' '.$this->cpage.' ';
for($i=1;$i<=$sum;$i++){
$page=$this->cpage+$i;
if($page<$this->pages)
$list.= ' <a href = "'.$this->url.'?page='.$page.'">'.$page.' </a>';
else
break;
}
return $list;
}
function last(){
$next = $this->cpage+1;
if($this->cpage < $this->pages)
return '<a href="'.$this->url.'?page='.$next.'">下一页</a> <a href="'.$this->url.'?page='.$this->pages.'">末页</a>';
}
}
function start (){
return ($this->cpage-1)*$this->tal+1;
}
function cend(){
return min($this->cpage*$this->tal,$this->total);
}
//本页显示的条数
function lastnum(){
return $this->cend() - $this->start() + 1;
}
/*function getmethod(){
return "共有{$this->pages}条记录,本页显示".$this->lastnum()."条记录,"." ".$this->start."-".$this->cend()."  ".$this->first()." ".$this->clist()." ".$this->last();
} //"共有{$this->totol}条记录,本页显示".$this->lastnum()."条 从".$this->start()."-".$this->end()." "."$this->cpage/{$this->pages}".$this->first()." ".$this->flist()." ".$this->last()." ";
*/
//调用此方法得到完整信息
function cpage(){
return "共有{$this->total}条记录,本页显示".$this->lastnum()."条 从".$this->start()."-".$this->cend()." "."$this->cpage/{$this->pages}".$this->first()." ".$this->clist()." ".$this->last()." ";
}
?>
这是另一个文件代码
<?php
include "page.class.php";
$b = new Page(85,10);
$b->a();
?>
求大神知道啊 ,这是什么问题啊,在线等 展开
<?php
class Page{
private $total; //总条数
private $pages; //总页数
private $tal; //每页的条数
private $url;
private $cpage; //当前页
function __construct($total,$tal){
$this->total = $total;
$this->tal = $tal;
$this->pages = $this->gettal();
$this->url="page1.php";
$this->cpage=!empty($_GET['page']) ? $_GET['page']:1;
}
function gettal(){
return ceil($this->total / $this->tal);
}
function first(){
$pre =$this->cpage-1;
if($this->cpage>1){
return '<a href="'.$this->url.'?page=1">首页</a> <a href="'.$this->url.'?page='.$pre.'">上一页</a>';
}
else return "";
}
function clist(){
$sum=4;
$list="";
for($i=$sum;$i>=1;$i--){
$page = $this->cpage-$i;
if($page>0)
$list.= ' <a href = "'.$this->url.'?page='.$page.'">'.$page.' </a>';
}
if($this->pages>1)
$list.= ' '.$this->cpage.' ';
for($i=1;$i<=$sum;$i++){
$page=$this->cpage+$i;
if($page<$this->pages)
$list.= ' <a href = "'.$this->url.'?page='.$page.'">'.$page.' </a>';
else
break;
}
return $list;
}
function last(){
$next = $this->cpage+1;
if($this->cpage < $this->pages)
return '<a href="'.$this->url.'?page='.$next.'">下一页</a> <a href="'.$this->url.'?page='.$this->pages.'">末页</a>';
}
}
function start (){
return ($this->cpage-1)*$this->tal+1;
}
function cend(){
return min($this->cpage*$this->tal,$this->total);
}
//本页显示的条数
function lastnum(){
return $this->cend() - $this->start() + 1;
}
/*function getmethod(){
return "共有{$this->pages}条记录,本页显示".$this->lastnum()."条记录,"." ".$this->start."-".$this->cend()."  ".$this->first()." ".$this->clist()." ".$this->last();
} //"共有{$this->totol}条记录,本页显示".$this->lastnum()."条 从".$this->start()."-".$this->end()." "."$this->cpage/{$this->pages}".$this->first()." ".$this->flist()." ".$this->last()." ";
*/
//调用此方法得到完整信息
function cpage(){
return "共有{$this->total}条记录,本页显示".$this->lastnum()."条 从".$this->start()."-".$this->cend()." "."$this->cpage/{$this->pages}".$this->first()." ".$this->clist()." ".$this->last()." ";
}
?>
这是另一个文件代码
<?php
include "page.class.php";
$b = new Page(85,10);
$b->a();
?>
求大神知道啊 ,这是什么问题啊,在线等 展开
展开全部
可能是作用域的问题
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
$b = new \Page(85,10);
这样试试
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2015-09-16
展开全部
实例化的时候看看方法名对不对
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
类的方法前加public
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询