TP5 Modify Paging Style

Keywords: PHP Javascript

Articles Catalogue

1. Modifying Style Files

Enter the paginator under the library folder under the thinkphp folder under the project root directory, open the dirver folder in the paginator folder, see a bootstrap.php file, copy the file, rename it Layui.php (customizable, capitalized, here named Layui.php), and modify the class name in Layui.php. For Layui(class Layui extends Paginator)

2. Modify Paging Style

Open the Layui.php file, find the render method (roughly 109 lines, annotated with rendering pagination), modify the return sprintf('the style you want', parameters, parameters (according to the number of your% s carry the same number of parameters, details please Baidu php sprintf function). Generally speaking, it is not enough to modify only here, you also need to modify getAvailable PageWra. Pper, getDisabled TextWrapper, getActivePageWrapper. Change their return values to the HTML code you need. That's all. Finally, the sample code is given.

3. Modify configuration files

Enter the application folder under the project and directory, and create config.php under the folder where you store background files (example: the api file under application is the processing interface, the admin folder is the background management system folder, and config.php is created under the admin folder, or can copy the config.php of application directly). Enter the code after building:

<?php
return [
    // +----------------------------------------------------------------------
    // | Application Settings
    // +----------------------------------------------------------------------
    
    //Paging configuration
    'paginate'               => [
        'type'      => 'Layui',//Change here to the style file you modified.
        'var_page'  => 'page'
        'list_rows' => 10,
    ],
];

4. Modify the query code

Modify the select statement in your controller to paginate ($this - > row (number of pages), false, $this - > param (parameters). Replace the static html code in the view layer with {list (parameters passed by assgin) - > render ()} to refresh the page.

5. Sample code

Layui.php part of the code:

/**
* Rendering Paging html
* @return mixed
*/
    public function render()
    {
        if ($this->hasPages()) {
            if ($this->simple) {
                return sprintf(
                    '<div class="layui-card-body">
                                <div class="page">
                                    <div>
                                     %s  %s
                                    </div>
                                </div>                              
                            </div>',
                    $this->getPreviousButton(),
                    $this->getNextButton()
                );
            } else {
                return sprintf(
                    '<div class="layui-card-body">
                                <div class="page">
                                    <div>
                                     %s   %s   %s
                                    </div>
                                </div>                              
                            </div>',
                    $this->getPreviousButton(),
                    $this->getLinks(),
                    $this->getNextButton()
                );
            }
        }
    }

    /**
     * Generate a clickable button
     *
     * @param  string $url
     * @param  int    $page
     * @return string
     */
    protected function getAvailablePageWrapper($url, $page)
    {
          return '<a class="num" href="' . htmlentities($url) . '" style="margin:1px">' . $page . '</a>';
    }

    /**
     * Generate a disabled button
     *
     * @param  string $text
     * @return string
     */
    protected function getDisabledTextWrapper($text)
    {
        return '<a class="prev" href="javascript:void(0);">' . $text .'</a>';
    }

    /**
     * Generate an Activated Button
     *
     * @param  string $text
     * @return string
     */
    protected function getActivePageWrapper($text)
    {
        return '<span class="current num" style="margin:2px">' . $text . '</span>';
    }

Controller code:

    public function lists()
    {
        $manager = new ManagerModel();
        $lists = $manager->where($this->_map)->paginate($this->_row,false,$this->_param);
        //... irrelevant code
        $this->assign('lists', $lists);//Pass parameters here
        return $this->fetch();//Return View
    }

View Layer Code:

    //Subject Content of ___________
    {$lists->render()}//paging

Origin Layer Code

    //Subject Content of ___________
    //Page Number Style (Replace with {$lists-> render ()})
    <div class="layui-card-body ">
        <div class="page">
            <div>
                <a class="prev" href="">&lt;&lt;</a>
                <a class="num" href="">1</a>
                <span class="current">2</span>
                <a class="num" href="">3</a>
                <a class="num" href="">489</a>
                <a class="next" href="">&gt;&gt;</a></div>
            </div>
    </div>

Posted by Brad420 on Thu, 29 Aug 2019 02:00:08 -0700