Home >Backend Development >PHP Tutorial >Fix thinkphp pagination with parameters_PHP tutorial

Fix thinkphp pagination with parameters_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 14:54:01846browse

Needless to say what thinkphp is, it is a lightweight PHP MVC framework. I worked on this thing a few days ago and made a photo album. I found that its paging is very confusing to me, especially the pagination with parameters.

Following its manual does not have much effect; later, looking directly at its paging class, it is not very complicated. After understanding its principle, it is just to separate the parameters in the $where array, pass them to the paging class in the GET method, and then combine these parameters into the query statement to implement parameterized paging. Then, I discovered that the name value passed in the $where array must be consistent with the name value in the form to do this. Otherwise, if it is passed over, it will not be received on the next page.

There is another question. There can be arrays in the $where array, such as $p=array('eq',$kid). If the variable $p is added to $where, Separating the parameters directly according to the manual does not seem to have any effect. When solving this problem, I wrote a function to determine whether it is an array, and then separate it, which is equivalent to recursion.

Another problem is that when paging is connected, the operation name of this page will be automatically added. That is to say, if it is /Index/Pager/ originally, it will become /Index/Pager/ after paging. Pager, this also makes me confused. I don’t know the reason.

In the end, I still didn’t follow the instructions in the manual. After thinking about it, isn't it just passing the parameters? It doesn't need to be so entangled. Modified its show() function, removed the URL parameter filtering function, and directly paging. For example, if the page is /Index/Pager, then use ushow("/Index/Pager") (modified), What you get is /Index/Pager/&p=2. Obviously p=2 is the second page. This can also be used for pagination without parameters. In fact, I just think that its paging is a bit tangled. Before I wrote the paging with parameters, I modified this function, and it happened to be used here. Then, just assemble the required parameters in the Action and pass them to the front desk. Where to go to the front desk, it must be in javascript. Then add this parameter to the tag after paging; part of the code:

$show = $Page->ushow(__URL__."/".$_REQUEST[C(VAR_ACTION) ]."/"); (Calling the assembled paging function actually encapsulates it, opens it, and handles it yourself.)

$output="/KID/".$kid. "/spbegintime/".$p["spbegintime"]."/spendtime/".$p["spendtime"]."/spname/".$p["spname"]; (In Action, assemble paging parameters; You can also use & to distinguish parameters. )

$this->assign('outpager',$output); bind page variables.

$("#pager a").click(function(){
var i=$("#pager a").index(this);
$("#pager a ").eq(i).attr("href",$("#pager a").eq(i).attr("href")+"{$outpager}");
}); front desk Modify the connection address and add parameters.

TP 2.1 was released recently, but I haven’t checked it out yet, hehe. I feel like, sometimes I feel uncomfortable using such a framework, and it seems like I am missing a feeling. It's the same with JQ. Sometimes I just use $("form").submit(); but in fact, JS is only used in one or two places on the page, and JQ is not loaded in; I was wondering if I would use it. JQ, let me forget about ordinary JS? This may be one of JQ's goals, haha. Of course, as a developer, you cannot be limited to one framework or one language.

Recently, I have been struggling to change ccmall.cn at work. Often, if I change it locally and upload it to the server, it will be useless. There is no way, I don’t have permission to modify the server, so I have to upload the changes. The person above will modify it on the server. cough. .

Sometimes I think that if a large-scale B2B or B2C website like ccmall.cn is successful, it will have to withstand at least tens of thousands of IPs and hundreds of thousands of PVs every day. For a subject like this, how can it be achieved? Will there be any problems in actual application? After all, there is a huge gap between the topics in universities and practical projects. Also, in the project, a large number of originally basic html tags are encapsulated into such complex server-side controls, and a large amount of ViewState is generated, which is very troublesome when modified. Is it necessary? In the process of modification, I often find that sometimes a server-side control that I put a lot of effort into writing is used in just one place. The function to be implemented can be achieved with a few basic JS and simple HTML tags. cough. .

After looking at some PHP projects, I feel that they are still simple, clear, concise and not bloated. . Microsoft likes to treat others as fools and encapsulate everything. (This only refers to asp.net). Of course, this does not mean that asp.net is useless, I just feel that many people do not use asp.net correctly. In fact, .net's strong types, compiled types, and generics, Ado.net, etc. are all very good, as well as the later launched asp.net MVC, including some new features introduced after .net 3.0, such as SQL CLR is quite practical for such logical database operations.

It’s a lot of verbosity, but I haven’t written it for a long time, hehe. Some of the above opinions are just personal opinions. If you don’t agree with them, you don’t have to worry about them. You are welcome to comment.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/364672.htmlTechArticleIt goes without saying what thinkphp is, a lightweight PHP MVC framework; I worked on this a few days ago I made a photo album and found that its pagination troubled me a lot, especially pagination with parameters. ...