phpcms custom tag paging in custom module

WBOY
Release: 2016-08-08 09:27:02
Original
963 people have browsed it

If you are an experienced phpcms secondary developer, you can ignore this article because the way it is written here feels disgusting
                                                                                                                                                                                                                                            . All posts need to be displayed on the forum list page and displayed in paging, according to the tag definition method in the phpcms default template
{pc:luntan action="get_send" num="2" page="$_GET[page]"} Follow This way of writing data['limit'] = '0,2' in the program but data[page] = NULL
This way the page number cannot be received, but due to personal research I don't understand how to implement the paging method in the system. Load it in and make it easy to use. I struggled for a long time and came up with a stupid trick. I hope you can correct me. If you have any good suggestions, I hope you can spare your time and teach me.
To get the list of forum posts, you need a method to get it, as follows

<span>public</span> <span>function</span> get_send(<span>$data</span><span>){
            </span><span>$page</span> = <span>empty</span>(<span>$_GET</span>['page']) ? 1 : <span>intval</span>(<span>$_GET</span>['page'<span>]);
            </span><span>$send_info</span> = <span>$this</span>->luntan_send->listinfo(<span>$where</span> = '', <span>$order</span> = '', <span>$page</span>, <span>$pagesize</span> = 20<span>);
            </span><span>//</span><span>$pages_send = $this->luntan_send->pages;</span>
            <span>for</span>(<span>$i</span> = 0; <span>$i</span> < <span>count</span>(<span>$send_info</span>); <span>$i</span>++<span>){
                </span><span>$type_info</span> = <span>$this</span>->luntan_type->get_one(<span>array</span>('type_id'=><span>$send_info</span>[<span>$i</span>]['send_type_id'<span>]));
                </span><span>$send_info</span>[<span>$i</span>]['send_type_name'] = <span>$type_info</span>['type_name'<span>];
                </span><span>$reply_info</span> = <span>$this</span>->luntan_reply->get_one(<span>array</span>('reply_send_id'=><span>$send_info</span>[<span>$i</span>]['send_id']),'count(*) as reply_send_num'<span>);
                </span><span>$send_info</span>[<span>$i</span>]['send_reply_num'] = <span>$reply_info</span>['reply_send_num'<span>];
            }
            </span><span>//</span><span>echo $pages_send;</span>
            <span>return</span> <span>$send_info</span><span>;
        }</span>
Copy after login

Pay attention to the echo $pages_send; in the line above the return. This is actually based on the paging method used in the background so that the page can display the page number normally and make jumps

But if you unlock this echo $pages_send;, then there is no way to do it. Control its display position on the page. In order to allow it to be displayed according to my wishes, I added another method below this method,

<span>public</span> <span>function</span> get_send_page(<span>$data</span><span>){
            </span><span>$page</span> = <span>empty</span>(<span>$_GET</span>['page']) ? 1 : <span>intval</span>(<span>$_GET</span>['page'<span>]);
            </span><span>$send_info</span> = <span>$this</span>->luntan_send->listinfo(<span>$where</span> = '', <span>$order</span> = '', <span>$page</span>, <span>$pagesize</span> = 20<span>);
            </span><span>$pages_send</span> = <span>$this</span>->luntan_send-><span>pages;
            </span><span>echo</span> <span>$pages_send</span><span>;
            </span><span>return</span> <span>$send_info</span><span>;
        }</span>
Copy after login

See the difference in the names of the two methods. There is a page difference between get_send and get_send_page. In this way, in terms of writing the function code inside, the latter only needs to display the page number, while the former only needs to display data, so you can use it in the get_send method. The call and output mask for getting the page number, that is,

//$pages_send = $this->luntan_send->pages;
...
//echo $pages_send;
In the latter get_send_page method, it does not The next for loop is needed to process the data. It doesn’t matter what data is returned. The main thing is to use the page echoed out, so the same part of the two functions is
$page = empty($_GET['page']) ? 1 : intval($_GET['page']);
$send_info = $this->luntan_send->listinfo($where = '', $order = '', $page, $pagesize = 20);
If you want to modify the number displayed on the default page, you need to modify one of the two methods
$send_info = $this->luntan_send->listinfo($where = '', $order = '', $page, $pagesize = 20);The $pagesize variable of a sentence

The above introduces the custom label paging of phpcms in the custom module, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template