ThinkPHP 3.2.2 Page.class.php 的修改

浏览:3040 发布日期:2014/12/02
自带Page类不能自由定制URL路由,很不方便,我希望可以定制成
/news-1.html或/news/1.html 这样的方式

Page类的简单修改如下:
增加个属性public $route = '';        //路由设置把show方法的这两行代码修改/* 生成URL */
$this->parameter[$this->p] = '[PAGE]';
$this->url = U(ACTION_NAME, $this->parameter);
修改为/* 生成URL */
if (!empty($this->route)) {
    if (stripos($this->route, '[PAGE]') !== false)
        unset($this->parameter[$this->p]);
    $this->url = str_replace('[page]', '[PAGE]', U($this->route, $this->parameter));
} else {
    $this->parameter[$this->p] = '[PAGE]';
    $this->url = U(ACTION_NAME, $this->parameter);
}
完成!


实例$page = new Page($count, 10);
//$page->route = '/news/[PAGE]'; //实现 news/1.html
$page->route = '/news-[PAGE]'; //实现 news-1.html
评论(
后面还有条评论,点击查看>>