If you are an experienced phpcms secondary developer, this article can be ignored because The writing here feels disgusting
Today I am developing a website and built a module called the forum module. Directory name: luntan
In the forum list page, all posts need to be displayed and displayed in paging. According to phpcms The label definition method in the default template is
{pc:luntan action="get_send" num="2" page="$_GET[page]"} According to this writing method, data['limit'] = '0, 2' But data[page] = NULL
can't receive the page number, but due to personal research I don't understand how to load the paging method in the system and make it easy to use. I struggled for a long time and came up with one. I'm confused, I hope you can correct me, and if you have any good suggestions, I hope you can spare your time and teach me
To get the list of forum posts, I need a method, 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>
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 jump
But if you unlock this echo $pages_send; then There is no way to 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>
See that the names of the two methods are different. 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 the get_send method can be The call and output mask used to obtain the page number, that is,
//$pages_send = $this->luntan_send->pages;
......
//echo $pages_send;
In the latter get_send_page method, there is no need for the next for loop to process the data. It does not 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 in the default page, you need to modify one of the two methods
$send_info = $this->luntan_send->listinfo ($where = '', $order = '', $page, $pagesize = 20);$pagesize variable in one sentence