smarty分配的变量为什么在模板上输出不了?
程序员文章站
2022-05-03 13:15:46
...
php smarty 分页 在网上找了一个分页类,加进自己需要的标签后,测试了一下,print_r可以打印输出,但是分配的到模板是空值,一时也没找到那出错了,请各位帮忙看看,急!
这个是修改的的分页类,pagediv.php
首页
上页 '; if($this->currentPage startHidden){ $content = ''; } return $content; } public function getPart2(){ $content = ' 1 '; $add = ''; if($this->currentPage > $this->startHidden){ $add = '...'; } if($this->currentPage == 1){ $content = '[1] '; $add = ''; } $part2 = $content.$add; return $part2; } public function getPart3(){ $content = ''; if($this->currentPage startHidden){ //[1] 2 3 4 5 6 7 8 9 10 ...100 下页 尾页 $long = $this->showPagesNo - 2; for($i=0;$icurrentPage){ $content .= '['.$this->currentPage.'] '; }else{ $content .= ' '.$j.' '; } } }elseif( $this->currentPage >= $this->endHidden ){ //首页 上页 1..92 93 94 95 96 97 98 [99] 100 $long = $this->showPagesNo - 2; $_start = $this->allPage - $long; for($i=0;$icurrentPage){ $content .= '['.$this->currentPage.'] '; }else{ $content .= ' '.$j.' '; } } }else{ //首页 上页 1..12 13 14 15 [16] 17 18 19 20 ...100 下页 尾页 $long = $this->showPagesNo - 2; $offset = $this->getInt($long/2) - 1; $_start = $this->currentPage - $offset; for($i=0;$icurrentPage){ $content .= '['.$this->currentPage.'] '; }else{ $content .= ' '.$j.' '; } } } $part3 = $content; return $part3; } public function getPart4(){ $content = ' '.$this->allPage.'
'; $add = ''; if($this->currentPage endHidden){ $add = '...'; } if($this->currentPage == $this->allPage){ $content = '['.$this->allPage.'] '; $add = ''; } $part4 = $add.$content; return $part4; } public function getPart5(){ $content = ' 下页
尾页
'; if($this->currentPage >= $this->endHidden){ $content = ''; } return $content; } public function show(){ //判断非法 if(!is_numeric($this->currentPage) || $this->currentPage currentPage > $this->allPage){ print 'error:pageNo is flase'; return; } //总页数没有达到显示分页栏的总页码数,则全部显示 if($this->allPage showPagesNo){ $long = $this->allPage; for($i=0;$icurrentPage){ $content .= '['.$this->currentPage.'] '; }else{ $content .= ''.$j.' '; } } print $content; return; } $this->part1 = $this->getPart1(); $this->part2 = $this->getPart2(); $this->part3 = $this->getPart3(); $this->part4 = $this->getPart4(); $this->part5 = $this->getPart5(); print $this->part1.$this->part2.$this->part3.$this->part4.$this->part5; } } ?>
Video.php
在模板上显示的时候不了。但是可以在模板打印。、
这个是修改的的分页类,pagediv.php
show(); */ class pagediv { public $part1; public $part2; public $part3; public $part4; public $part5; /* 对下面的分页显示进行分割: 首页 上页 1..12 13 14 15 [16] 17 18 19 20 ...100 下页 尾页 $part1 : 首页 上页 $part2 : 1.. $part3 : 12 13 14 15 [16] 17 18 19 20 $part4 : ...100 $part5 : 下页 尾页 */ public $allPage; //总页数 public $allRocords; //总记录数 public $perPage; //每页记录数 public $showPagesNo; //显示分页栏的总页码数 显示样式里共有11个 public $currentPage; //当前页 public $urlModel; //Url链接样式 public $startHidden; //出现 1... 时的页数 开始隐藏中间页 public $endHidden; //出现 ...100 时的页数 结束隐藏中间页 public function __construct($allRocords, $perPage, $showPagesNo, $currentPage, $urlModel){ $this->allRocords = $allRocords; $this->perPage = $perPage; $this->showPagesNo = $showPagesNo; $this->currentPage = $currentPage; $this->urlModel = $urlModel; $this->allPage = $this->getAllPage(); $this->startHidden = $this->getInt(($this->showPagesNo)/2); //6 $this->endHidden = $this->allPage - $this->startHidden; //94 } public function getUrl($_index = ''){ $_current = $_index; if($_index == 'pre') $_current = $this->currentPage -1; if($_index == 'next') $_current = $this->currentPage+1; if($_index == '') $_current = $this->allPage; return $this->urlModel.$_current; } public function getAllPage(){ return $this->getInt($this->allRocords/$this->perPage); } public function getInt($_float){ $_int = $_float; if( $_index = strpos($_float,'.') == true ){ $_int = substr($_float,0,$_index); $_int++; } //没有想起ceil时的候补方案 return $_int; } public function getPart1(){ $content = '
Video.php
$currentPage = $_GET['page']?$_GET['page']:1; $pagediv = new pagediv(500, 10, 5, $currentPage, 'Video.php?page='); $pages=$pagediv->show(); $smarty->assign('pages',$pages);$smarty->display('Video.html');
在模板上显示的时候不了。但是可以在模板打印。、
- {$pages}
回复讨论(解决方案)
模板中是否有包含特殊的标记,smarty不识别。
分页类有问题。你可以用这个试试。
第%page%页/共%pageToatl%页
上一篇: c#如何生成二维码的示例分享
下一篇: 大家帮忙看下这段代码哪有问题