Thinkphp Verification Code and pagination example tutorial, thinkphp example Tutorial
This paper describes the two common functions of thinkphp: Verification code and paging. It is very common in the project development of thinkphp and has high practical value. A complete example is shared with everyone for your reference. Specific as follows:
First, Verification code:
Import verification Code class, there is a verification code method in aoli\thinkphp\lib\org\util\image.class.php
1. English Verification Code:
Buildimageverify ($length, $mode, $type, $width, $height, $verifyName)
The parameters are as follows:
Length: Number of verification codes, default to 4 digits
Mode: Verify string type, default to number, other support type has 0 letter 1 digit 2 Capital Letter 3 Lowercase Letter 4
Chinese 5 Mix (remove the easily confusing characters Ooll and number 01)
Type: A picture of the CAPTCHA, default to PNG
Width: Verification code, the default is automatically based on the length of the verification code automatically calculated
Height: The high of the Verification Code, which defaults to 22
VerifyName: The SESSION record name of the verification code, the default is verify
2. Chinese Verification Code:
Gbverify ($length, $type, $width, $height, $fontface, $verifyName)
The parameters are as follows:
Length: Number of verification codes, default to 4 digits
Type: A picture of the CAPTCHA, default to PNG
Width: Verification code, the default is automatically based on the length of the verification code automatically calculated
Height: The high of the Verification Code, which defaults to 50
Fontface: The font file used, using the full file name or placed under the directory where the image class resides, the default font file used is Simhei.ttf (the file can be found under the Fonts Directory of window)
VerifyName: The SESSION record name of the verification code, the default is verify
3. If the verification code cannot be displayed, please check:
①.php has installed GD library support;
②. Is there any output before the output (especially the UTF8 BOM header information output);
Whether the ③.image class library is imported correctly;
④. If it is a Chinese code check if there is a copy font file to the directory where the class library is located;
4.action part:
The CommonAction.class.php page code is as follows:
<?phpclass commonaction extends action{ function verify () { import (' ORG. Util.image '); English Verification Code //image::buildimageverify (5,5,gif,90,30, ' verify '); Chinese Verification Code image::gbverify (); } }? >
5.view Template section:
The template Index.html page is as follows:
Verification Code:
6. Controller:
The controller UserAction.class.php is as follows:
Verification Code verification if ($_session[' verify ']!=md5 ($_post[' verify ')) { $this->error (' incorrect captcha '); }
Second, paging:
1. Import the paging class, there is a verification code method in the Aoli\thinkphp\lib\org\util\page.class.php
2.action part:
The UserAction.class.php page is as follows:
function index () { import (' ORG. Util.page ');//Introduce the distribution class $user =m (' user '); $count = $user->count (); $page =new page ($count, 3);//page showing 5 $page->setconfig (' theme ', ' Total:%totalrow%%header%%nowpage%/%totalpage% page% first%%uppage%%prepage%%linkpage%%nextpage%%downpage%%end% '); $show = $page->show (); $list = $user->field (array (' ID ', ' username ', ' createip '))->order (' id desc ')->limit ($page->firstrow. ', '. $page->listrows)->select (); $this->assign (' alist ', $list); $this->assign (' page ', $show); $this->display ();}
3.view Template section:
The index.html page of the template page is as follows:
ID: {$VO [' id ']} User name: {$vo [' username ']} Registered IP: {$vo [' Createip ']} Delete edit
{$page}
Interested readers can debug run this article thinkphp verification code and paging instances, I believe there will be new harvest.
How to change page paging, thinkphp kernel, examples such as: http://wwwttplmgcom/special/8html
Use the Setconfig method in the pagination class to customize the page-out style:
I have a previously used custom paging class, you see this change.
/** * * Enter Public Paging class * @param array $map page filter conditions * @param class $Form Data Model * @param number of bars displayed in integer $limit page * @param string $ Order sort * @return Array */Public function _list ($map, $Form, $limit =9, $order = ' add_time ') {$res =array (); $p =empty ($_get[' P '])? 0: (int) $_get[' P ']; $res [' list '] = $Form->field (True)->where ($map)->order ($order)->page ($p. ', '. $limit)->select (); Import (' ORG. Util.page '); Import Paging Class $count = $Form->where ($map)->count ();//query satisfies the required total number of records $page = new page ($count, $limit);//Instantiate paging class Number of incoming total records and number of records displayed per page $page->rollpage=3; $Page->setconfig (' theme ', "%uppage%%linkpage%%downpage%
%nowpage%/%totalpage% page </a></li> "), $res [' page '] = $Page->show ();//pagination display output return $res; }
thinkphp how to get the next page of the last page of the transfer variable is I want to use the original paging effect to attach the page effect to the picture
public function index () {//change the icon to a style $user = M (' user '); Import (' ORG. Util.page '); $count = $user->count (); $listRows = 5; $page = new Page ($count, $listRows); $list = $user->limit ("{$page->firstrow},{$page->listrows}")->select (); $page->setconfig (' prev ', ');//Previous page $page->setconfig (' next ');//Next page//$page->setconfig (' first ', '); $page->setconfig (' last ', '); $page->setconfig (' theme ', '%uppage%%downpage% ');//display only the upper and lower page options $this->assign (' page ', $page->show ()); $this->assign (' list ', $list); $this->display ();}
http://www.bkjia.com/PHPjc/868240.html www.bkjia.com true http://www.bkjia.com/PHPjc/868240.html techarticle thinkphp Verification Code and pagination example tutorial, thinkphp example Tutorial This article describes the thinkphp commonly used two functions: Verification code and paging. Very common in thinkphp project development, with ...