Handle thinkphp pagination with parameters. Thinkphp is nothing to say, a lightweight PHPMVC framework. a few days ago, I made a photo album and found that the paging of thinkphp made me tangle, especially with the paging of parameters. Thinkphp is nothing to say, a lightweight php mvc framework. a few days ago, I made a photo album and found that its paging made me tangle, especially the paging with parameters.
According to its manual, there was little effect. later, it was not very complicated to look at its paging class directly. After understanding its principle, it simply splits the parameters in the $ where array and passes them to the paging class in the GET method, then, these parameters are combined into the query statement to implement pagination with parameters. Then, we can find that the value passed in the $ where array must be consistent with the name value in the form before doing so. Otherwise, it cannot be received when it is passed to the next page.
Another problem is that there can be arrays in the $ where array, for example, $ p = array ('EQ ', $ kid ), if this variable $ p is added to $ where, it does not seem effective to directly separate the parameters according to the manual. To solve this problem, I wrote another function to determine whether it is an array and then separate it, which is equivalent to a recursion.
Another problem is that the operation name on this page will be automatically added during paging connection, that is, if it was originally/Index/Pager/, after paging, it will become/Index/Pager, which also makes me tangle and do not know why.
Finally, I still did not follow the instructions in the manual. After thinking about it, it is not just to pass the parameter, but it needs to be so tangled. Modified its show () function and removed the URL parameter filtering function, which is directly paging. for example, if the page is/Index/Pager, use ushow ("/Index/Pager") (modified) to obtain/Index/Pager/& p = 2. Obviously, p = 2 is the second page. This can also be used for paging without parameters. In fact, I think the paging is a bit tangled. I modified this function before writing it to the page with parameters. that's exactly what I used here. Then, we need to assemble the required parameters in the Action and pass them to the front-end. Where should we go to the front-end? it must be in javascript. Then add this parameter to the tag after pagination. some code:
$ Show = $ Page-> ushow (/index. php/Article. "/". $ _ REQUEST [C (VAR_ACTION)]. "/"); (calling the assembled paging function is actually encapsulating it, opening it again, and processing it by yourself .)
$ Output = "/KID /". $ kid. "/spbegintime /". $ p ["spbegintime"]. "/spendtime /". $ p ["spendtime"]. "/spname /". $ p ["spname"]; (in the Action, assemble the paging parameters. you can also use & to differentiate parameters .)
$ This-> assign ('outpager', $ output); bind the page variable.
$ ("# Pager a"). click (function (){
Var I = $ ("# pager a"). index (this );
$ ("# Pager "). eq (I ). attr ("href", $ ("# pager "). eq (I ). attr ("href") + "{$ outpager }");
}); The frontend changes the connection address and adds the parameters.
Recently, the TP output is 2.1, so I haven't checked it yet. hey. Feel it, sometimes using such a framework will become unaccustomed, it seems that there is a feeling of being lost. The same is true with JQ. sometimes it is customary to use $ ("form "). submit (); in fact, JS is used in one or two pages, and JQ is not loaded in. I am all wondering if JQ will be used to make me forget the common JS? This may be one of JQ's goals, haha. Of course, as a developer, it cannot be limited to only one framework or language.
Recently, ccmall.cn is also Tangled. it is often because it is locally modified and uploaded to the server, it is useless. No way, I have no permission to modify the server. I have to upload the changed files to the server, the above person then modifies the server. Cough ..
Sometimes I think that a large B2B and B2C website like ccmall.cn has succeeded. every day, at least tens of thousands of IP addresses and hundreds of thousands of PVs are required, is there a problem when I get it in practical use? After all, there is a huge gap between the subjects in the university and the projects actually used. In addition, in the project, a large number of basic html tags are encapsulated into complicated server-side controls to generate a large number of viewstates, which is troublesome when being modified. Is it necessary? During the modification process, it is often found that sometimes a server control that is written with great effort is used in one place, and the functions to be implemented, A few basic JS statements and simple HTML tags can be used. Cough ..
I looked at some PHP projects and thought they were simple, concise, and not bloated .. Microsoft prefers to treat others as fools and encapsulate everything. (Asp.net only ). Of course, it doesn't mean that asp.net is useless. I just think that many people do not use asp.net correctly. Actually ,. net strongly typed, compiled, generic, and Ado.net are all very good, and asp.net MVC was launched later, including. some new features introduced after net3.0, such as SQL CLR, are quite practical for logic-heavy database operations.
I have been reading a lot, but I haven't written it for a long time. Some of the above points are just some of my personal opinions. if you don't agree with them, you don't have to work hard.
Using MVC framework; a few days ago, I made an album and found that its paging made me tangle, especially the paging with parameters ....