zoukankan      html  css  js  c++  java
  • 问题: 在使用thinkphp自带分页类时,在设置尾页显示的最后一页时,用setConfig(“last”,”尾页”)来设置样式,发现无效。

    分析: 
    在分页类(/ThinkPHP/Library/Think/Page.class.PHP)里面有一个共有属性:

    public $lastSuffix = true; // 最后一页是否显示总页数

    在show方法的实现中:

    $this->lastSuffix && $this->config['last'] = $this->totalPages;

    所以如果$lastSuffix = true的话,setConfig(‘last’,’尾页’)的设置会被重置,也就是说,我们的setConfig(“last”,”尾页”)被覆盖了。

    解决方法: 
    1、我们可以在分页类里面直接修改属性:

    public $lastSuffix = false;

    但是,我们不知道类中在其他地方是否有使用到$lastSuffix这个变量,因此,为了不影响整个类,我们可以修改setConfig()方法

    2、修改setConfig(): 
    修改前:

    public function setConfig($name,$value) {
                   if(isset($this->config[$name])) {
                     $this->config[$name] = $value;
                   }
             }

    修改后:

    public function setConfig($name,$value) {
            if(isset($this->config[$name])) {
                $this->config[$name] = $value;
                if($name == 'last'){
                   $this->lastSuffix = false;
                }
            }
       }

    好了,现在我们的setConfig(“last”,”尾页”);已经能够正常工作了。

  • 相关阅读:
    HashMap:JDK7 与 JDK8 的实现
    es简单介绍及使用注意事项
    mongo学习使用记录2 spring data
    mongo学习使用记录1
    数据库三范式
    mysql数据库中实现内连接、左连接、右连接
    JDK7与JDK8中HashMap的实现
    字符串按照相似度排序
    Linux shell 脚本小记2
    ReentrantLock源码了解
  • 原文地址:https://www.cnblogs.com/lichihua/p/5775673.html
Copyright © 2011-2022 走看看