搞定thinkphp带参分页
thinkphp是什么就不用多说了,一个轻量级的PHP MVC框架;前几天搞搞这个东西,做了个相册,发现,它的分页很让我纠结,特别是带参分页。
按照它的手册来吧,没多大效果;后来,直接看它的分页类,也不是很复杂。搞明白了它的原理,只不过就是将$where数组中的参数,分离,以GET的方式,传递到分页类中,然后再将这些参数又组合到查询语句中,实现带参分页。然后,才发现,在$where数组中传递的,和表单中的name值要一致,才能这样做。否则的话,传递过来,到了下一页,是收不到的。
还有一个问题,$where数组中,是可以再有数组的,好比有$p=array('eq',$kid),这个变量$p再添加到$where中的话,直接按手册上的来分离参数,似乎也没效果。解决这个问题时,又写了个函数,判断是不是数组,然后再分离,相当于一个递归。
还有个问题就是,分页连接的时候,会自动加上本页的操作名,就是说,本来是/Index/Pager/的话,分页后,会变成/Index/Pager/Pager,这也让我纠结,不知道原因在哪里。
最后呢,还是没有按照手册上的方法弄好。想了想,不就是把参数传递过去嘛,需要那么纠结嘛。改装了一下它的show()函数,去掉了URL参数过滤这个功能,直接就是分页,比如说,页面是/Index/Pager,那么,使用ushow("/Index/Pager")(改装后的),得到的就是/Index/Pager/&p=2,很明显p=2就是第二页。这个也可以用于不带参的分页。实际上,我就是觉得它这个分页有点纠结,在还没有写到带参分页的时候,我就改装了这个函数,正好,这里用上了。然后呢,就是把需要的参数在Action里面组装一下,传递到前台,到前台哪里呢,肯定是javascript里面。然后再将这个参数,添加到分页后的标签里面;部分代码:
$show = $Page->ushow(__URL__."/".$_REQUEST[C(VAR_ACTION)]."/");(调用组装后的分页函数,实际上,就是将它封装好的,又打开,自己处理。)
$output="/KID/".$kid."/spbegintime/".$p["spbegintime"]."/spendtime/".$p["spendtime"]."/spname/".$p["spname"];(Action里面,组装分页参数;也可以用&来区分参数。)
$this->assign('outpager',$output);绑定页面变量。
$("#pager a").click(function(){
var i=$("#pager a").index(this);
$("#pager a").eq(i).attr("href",$("#pager a").eq(i).attr("href")+"{$outpager}");
});前台修改连接地址,将参数加进来。
最近TP出2.1了,还没去看,嘿嘿。感觉吧,有时候用这样的框架,会不习惯,似乎就是少了一种感觉。用JQ也一样,有时候就习惯性的$("form").submit();而其实页面中就一两处用到了JS,都没把JQ加载进来;我都在想,会不会使用JQ,让我把普通JS给忘了?这也许就是JQ的目标之一吧,哈哈。当然,作为开发者的话,不能只局限于一个框架,一种语言。
最近上班改ccmall.cn也纠结,常常就是本地改好了,上传到服务器上,就没用了;没办法,服务器我没权限修改,我得将改好的往上传,上面的人再修改服务器上的。咳。。
有时候在想,像ccmall.cn这样的大型B2B,B2C网站,做成功了,每天至少是要经受上万IP,数十万次PV的,像这样一个课题,弄到实际运用中去,会不会有问题?毕竟大学里面的课题和实际运用的项目,差距是非常大的。还有,项目中,将大量的,本来最基本的html标签,封装成那么复杂的服务端控件,生成大量的ViewState,然后修改的时候,就N麻烦。有必要么?在修改的过程中,经常就发现,有时候,花大力气写的一个服务端控件,就一个地方用到了,要实现的功能,完全可以几句很基本的JS和简单的HTML标签搞定。咳。。
看了看一些PHP项目,觉得还是那种简单明了,简洁,不臃肿。。微软就喜欢把别人当傻瓜,什么都封装好。(这里仅仅指asp.net)。当然了,也不是说asp.net一无是处哈,只是觉得,好多人都没有正确的运用asp.net就是。其实,.net的强类型,编译型,以及泛型,Ado.net等都是非常不错的,还有后来推出的asp.net MVC,包括.net3.0之后推出来的一些新特性,像SQL CLR,这样重逻辑的数据库操作,还是挺实用的。
啰嗦了好多,只是好久没写了,嘿嘿。以上某些观点只是个人的一些见解哈,如果你不认同,大可不必上劲哈,欢迎拍砖。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

In PHP, you can effectively prevent CSRF attacks by using unpredictable tokens. Specific methods include: 1. Generate and embed CSRF tokens in the form; 2. Verify the validity of the token when processing the request.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7
