Skip to content
网游世界
网游世界

吾生有涯,而知无涯。

  • 首页
  • PHP
    • ThinkPHP
    • FastAdmin
    • webman
  • JavaScript
    • jQuery
    • AdminLTE
  • Free Pascal
  • Java
    • JeeSite
    • 若依
    • ruoyi-vue-pro
  • 其它
    • 操作系统
    • 树莓派
    • 前端
    • Null
  • 关于
网游世界

吾生有涯,而知无涯。

webman 会员中心分页展示

3Vshej, 2024年1月12日 周五2024年1月12日 周五

webman 中仅提供了核心功能,但在日常开发中,并没有附加的组件,需要手动安装。

在会员中心(前台插件开发)时,需要用到分页,官方提供了分页使用方法。

这里介绍下,实际使用时要做的调整:

我使用了 illuminate/pagination 组件。官方说,不支持 $paginator->links() 方法,需要使用第三方插件来实现,如 jasongrimes/paginator。

通过:

composer require jasongrimes/paginator

来安装。但在使用时,渲染分页时,插件是基于 bootstrap v3 版本的,webman 是基于 bootstrap v4 版本的。因此需要调整分页渲染方式:

打开 vendor/jasongrimes/paginator/src/JasonGrimes/Paginator.php,修改 toHtml() 方法:

/**
 * Render an HTML pagination control.
 *
 * @return string
 */
public function toHtml()
{
    if ($this->numPages <= 1) {
        return '';
    }

    $html = '<ul class="pagination">';
    if ($this->getPrevUrl()) {
        $html .= '<li class="page-item"><a class="page-link" href="' . htmlspecialchars($this->getPrevUrl()) . '" rel="external nofollow">&laquo; ' . $this->previousText . '</a></li>';
    }

    foreach ($this->getPages() as $page) {
        if ($page['url']) {
            $html .= '<li' . ($page['isCurrent'] ? ' class="active page-item"' : '') . '><a class="page-link" href="' . htmlspecialchars($page['url']) . '" rel="external nofollow">' . htmlspecialchars($page['num']) . '</a></li>';
        } else {
            $html .= '<li class="disabled page-item"><span class="page-link">' . htmlspecialchars($page['num']) . '</span></li>';
        }
    }

    if ($this->getNextUrl()) {
        $html .= '<li class="page-item"><a class="page-link" href="' . htmlspecialchars($this->getNextUrl()) . '" rel="external nofollow">' . $this->nextText . ' &raquo;</a></li>';
    }
    $html .= '</ul>';

    return $html;
}

控制中,使用:

public function list(Request $request)
{

    /** @var int $perPage 分页大小 */
    $perPage = 10;

    $list = (new Client())
        ->where('user_id', session('user.id'))
        ->orderBy('id', 'desc')->paginate($perPage);

    $paginator = new Paginator(
        $list->total(),
        $perPage,
        $request->get('page'),
        '/app/oauth/index/list?page=(:num)');

    $paginator->setMaxPagesToShow(5);
    $paginator->setNextText('下一页');
    $paginator->setPreviousText('上一页');

    return view('index/list', ['list' => $list, 'count' => $list->total(), 'paginator' => $paginator]);
}

模板中,输出 $paginator 变量即可。

参考来源:

  • 解决在 webman 中使用 jasongrimes/paginator 分页组件与 Bootstrap 4 兼容性问题
  • PHP分页组件:Paginator

相关文章:

  1. webman 用户模块增加菜单 webman 是一款基于 workerman 开发的 HTTP 服务框架,支持自定义进程,数据库,R......
  2. PHP OAuth2 OAuth 不是一个 API 或者服务,而是一个验证授权(Authorization)的开放标准,所......
  3. PHP OAuth2 Server 刷新授权 访问令牌最终会过期;但是,某些授权使用刷新令牌进行响应,使客户端能够刷新访问令牌。...
  4. PHP OAuth2 Server 授权服务器事件 在通过授权服务器的请求的生命周期中,可能会发出许多事件。 您可以通过将侦听器附加到授权服务器来订阅这......
PHP webman PHPwebman分页插件

文章导航

Previous post
Next post

近期文章

  • Android Studio Gradle 配置国内镜像
  • 为什么重新发明轮子
  • ruoyi-vue-pro 匿名访问
  • VUE 中接收 code 异常
  • 关于 AI

归档

  • 2025 年 4 月
  • 2025 年 3 月
  • 2025 年 2 月
  • 2025 年 1 月
  • 2024 年 12 月
  • 2024 年 11 月
  • 2024 年 10 月
  • 2024 年 9 月
  • 2024 年 8 月
  • 2024 年 7 月
  • 2024 年 6 月
  • 2024 年 5 月
  • 2024 年 4 月
  • 2024 年 3 月
  • 2024 年 2 月
  • 2024 年 1 月
  • 2023 年 12 月
除非特殊说明,本站作品采用知识共享署名 4.0 国际许可协议进行许可。
豫公网安备 41010402002622号 豫ICP备2020029609号-3
©2025 3Vshej