ThinkPHP verification code and paging example tutorial, thinkphp example tutorial_PHP tutorial

WBOY
Release: 2016-07-13 10:20:06
Original
930 people have browsed it

ThinkPHP verification code and paging example tutorial, thinkphp example tutorial

The examples in this article describe two commonly used functions of ThinkPHP: verification code and paging. It is very common in ThinkPHP project development and has high practical value. The complete example is shared with everyone for your reference. The details are as follows:

1. Verification code:

Import the verification code class, there is a verification code method in aoliThinkPHPLibORGUtilImage.class.php

1. English verification code:

buildImageVerify($length,$mode,$type,$width,$height,$verifyName)
Copy after login

The parameters are as follows:

length: The length of the verification code, the default is 4 digits
mode: The type of verification string, the default is number, other supported types are 0 letters 1 numbers 2 uppercase letters 3 lowercase letters 4
Chinese 5 mixed (removed the confusing character oOLl and the number 01)
type: The image type of the verification code, the default is png
width: The width of the verification code. By default, it will be automatically calculated based on the length of the verification code
height: the height of the verification code, the default is 22
verifyName: SESSION record name of the verification code, the default is verify

2. Chinese verification code:

GBVerify ($length,$type,$width,$height,$fontface,$verifyName)
Copy after login

The parameters are as follows:

length: The length of the verification code, the default is 4 digits
type: The image type of the verification code, the default is png
width: The width of the verification code. By default, it will be automatically calculated based on the length of the verification code
height: the height of the verification code, the default is 50
fontface: The font file used, use the complete file name or put it in the directory where the image class is located. The default font file used is simhei.ttf (this file can be found under the Fonts directory of the window)
verifyName: SESSION record name of the verification code, the default is verify

3. If the verification code cannot be displayed, please check:

①.PHP Whether GD library support has been installed;
②. Is there any output before output (especially the BOM header information output of UTF8);
③.Is the Image class library imported correctly?
④. If it is a Chinese verification code, check whether the font file has been copied to the directory where the class library is located;

4.action part:

CommonAction.class.php page code is as follows:

<&#63;php
class CommonAction extends Action{
  function verify(){    
    import('ORG.Util.Image');
    //英文验证码
    //Image::buildImageVerify(5,5,gif,90,30,'verify');
    //中文验证码
    Image::GBVerify();
  }  
  
}
&#63;>

Copy after login

5.view template part:

The template index.html page is as follows:

 验证码:<input type="text" name="verify" /><img src="__APP__/common/verify" onclick="show(this)" /><br />
 <input type="submit" value="注册" />
</form>

<script type="text/javascript">
  function show(obj){
    obj.src="__APP__/common/verify/random/"+Math.random();    
  }
</script>

Copy after login

6. Controller:

The controller UserAction.class.php is as follows:

//验证码验证
if($_SESSION['verify']!=md5($_POST['verify'])){
  $this->error('验证码不正确');   
}

Copy after login

2. Pagination:

1. Import the paging class, there is a verification code method in aoliThinkPHPLibORGUtilPage.class.php

2.action part:

UserAction.class.php page is as follows:

function index(){
  import('ORG.Util.Page');//引入分布类
  $user=M('user');
  $count=$user->count();
  $page=new Page($count,3);//一页显示5条
  $page->setConfig('theme','<div style="font-weight:bold;">总共:%totalRow%%header% %nowPage%/%totalPage%页 %first% %upPage% %prePage% %linkPage% %nextPage% %downPage% %end%</div>');
  $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();
}

Copy after login

3.view template part:

The template page index.html page is as follows:

<volist name="alist" id="vo">
 <li><span>ID:</span>{$vo['id']}<span>用户名:</span>{$vo['username']}<span>注册ip:</span>{$vo['createip']}<a href="__URL__/del/id/{$vo['id']}">删除</a>  <a href="__URL__/edit/id/{$vo['id']}">编辑</a></li>
</volist>
{$page}

Copy after login

Interested readers can debug and run the ThinkPHP verification code and paging examples in this article. I believe there will be new gains.

How to change web page paging, THINKPHP core, for example: http://wwwttplmgcom/special/8html

Use the setConfig method in the paging class to customize the paging style:
I have a custom paging class that I used before. You can change it here.

/** * * Enter public paging class* @param array $map paging filtering conditions* @param class $Form data model* @param integer $limit number of items displayed in paging* @param string $order Sorting* @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 the total number of records that meet the requirements $Page = new Page($count,$limit);// Instantiate the paging class and pass in the total number of records and the number of records displayed on each page $Page-> rollPage=3;$Page->setConfig('theme'," %upPage% %linkPage% %downPage%

  • %nowPage%/%totalPage% page
  • ");$res['page'] = $Page->show();// Display output in paging return $res; }

    How to get the transfer variables of the previous page and next page when thinkphp is paginating? I want to attach the upper and lower page effects to the picture without using the original paging effect.

    public function index() {//Just change the style of the icon $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%');// Only display the upper and lower page options $this->assign('page', $page->show()); $this->assign('list', $list); $this->display(); }

    www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/868240.htmlTechArticleThinkPHP verification code and paging example tutorial, thinkphp example tutorial This article describes two commonly used functions of ThinkPHP: verification code with pagination. It is very common in ThinkPHP project development, with...
    source:php.cn
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template