mirror of
https://gitee.com/ulthon/ulthon_information.git
synced 2026-07-09 09:32:47 +08:00
完成分页优化
This commit is contained in:
21
app/common/Bootstrap.php
Normal file
21
app/common/Bootstrap.php
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\common;
|
||||||
|
|
||||||
|
use think\paginator\driver\Bootstrap as DriverBootstrap;
|
||||||
|
|
||||||
|
class Bootstrap extends DriverBootstrap
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取页码对应的链接
|
||||||
|
*
|
||||||
|
* @access protected
|
||||||
|
* @param int $page
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function url(int $page): string
|
||||||
|
{
|
||||||
|
return (string)url($this->options['url'], ['page' => $page]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,17 +3,18 @@
|
|||||||
namespace app\index\controller;
|
namespace app\index\controller;
|
||||||
|
|
||||||
use app\BaseController as AppBaseController;
|
use app\BaseController as AppBaseController;
|
||||||
use think\facade\Config;
|
use app\common\Bootstrap;
|
||||||
use think\facade\View;
|
use think\Paginator;
|
||||||
use think\helper\Str;
|
|
||||||
|
|
||||||
class BaseController extends AppBaseController
|
class BaseController extends AppBaseController
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
public function initialize()
|
public function initialize()
|
||||||
{
|
{
|
||||||
parent::initialize();
|
parent::initialize();
|
||||||
|
|
||||||
|
Paginator::maker(function($items, $listRows, $currentPage, $total, $simple, $options){
|
||||||
|
return new Bootstrap($items, $listRows, $currentPage, $total, $simple, $options);
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,8 @@
|
|||||||
namespace app\index\controller;
|
namespace app\index\controller;
|
||||||
|
|
||||||
use app\model\Category;
|
use app\model\Category;
|
||||||
use app\model\Nav;
|
|
||||||
use app\model\Post;
|
use app\model\Post;
|
||||||
use app\model\PostCategory;
|
use app\model\PostCategory;
|
||||||
use think\facade\Route;
|
|
||||||
use think\facade\View;
|
use think\facade\View;
|
||||||
use think\Request;
|
use think\Request;
|
||||||
|
|
||||||
@@ -36,7 +34,6 @@ class Index extends Common
|
|||||||
$model_post = Post::hasWhere('categorys', $categorys_where)->where('status', 1)->order('id desc');
|
$model_post = Post::hasWhere('categorys', $categorys_where)->where('status', 1)->order('id desc');
|
||||||
} else {
|
} else {
|
||||||
$model_post = Post::hasWhere('categorys', ['category_id' => $this->request->param('sub_category_id')])->where('status', 1)->order('id desc');
|
$model_post = Post::hasWhere('categorys', ['category_id' => $this->request->param('sub_category_id')])->where('status', 1)->order('id desc');
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@@ -51,7 +48,8 @@ class Index extends Common
|
|||||||
$model_post->whereLike('title|desc', "%$keywords%");
|
$model_post->whereLike('title|desc', "%$keywords%");
|
||||||
}
|
}
|
||||||
|
|
||||||
$list_post = $model_post->paginate();
|
|
||||||
|
$list_post = $model_post->paginate(['url' => 'Index/index']);
|
||||||
|
|
||||||
View::assign('current_category', $current_category);
|
View::assign('current_category', $current_category);
|
||||||
View::assign('sub_category', $sub_category);
|
View::assign('sub_category', $sub_category);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ namespace app\model;
|
|||||||
|
|
||||||
use think\Model;
|
use think\Model;
|
||||||
use think\model\concern\SoftDelete;
|
use think\model\concern\SoftDelete;
|
||||||
|
use think\Paginator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @mixin think\Model
|
* @mixin think\Model
|
||||||
@@ -143,4 +144,5 @@ class Post extends Model
|
|||||||
|
|
||||||
return $url_info['scheme'].'://'.$url_info['host'].'/a'.$this->getData('uid').'.html';
|
return $url_info['scheme'].'://'.$url_info['host'].'/a'.$this->getData('uid').'.html';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,6 +86,7 @@
|
|||||||
<img class="nodata" src="/static/images/nodata.png" alt="">
|
<img class="nodata" src="/static/images/nodata.png" alt="">
|
||||||
{/empty}
|
{/empty}
|
||||||
</div>
|
</div>
|
||||||
|
{$list_post->render()|raw}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user