当前位置: 代码迷 >> PHP >> ThinkPHP学习札记(十二)ThinkPHP的分页以及验证码的使用
  详细解决方案

ThinkPHP学习札记(十二)ThinkPHP的分页以及验证码的使用

热度:9   发布时间:2016-04-28 22:04:34.0
ThinkPHP学习笔记(十二)ThinkPHP的分页以及验证码的使用

CommonAction

<?php/** * ThinkPHP中的 * 让其他的Action继承当前的CommonAction就可以了 */class CommonAction extends Action{	public function verify(){		//导入验证码类		//方式一:		import('ORG.Util.Image');		//方式二:@代表当前项目的lib文件夹(需要自己复制或者自己写一个新的类)//		import('@.ORG.Image')//		Image::buildImageVerify();				//扩展修改 		/**		 * @param string $length  位数		 * @param string $mode  类型(0字母,1数字,2大写字母,3小写字母,4中文,5混合)		 * @param string $type 图像格式		 * @param string $width  宽度		 * @param string $height  高度		 * buildImageVerify($length=4,$mode=1,$type='png',$width=48,$height=22,$verifyName='verify')		 */		Image::buildImageVerify(5,5,'png',80,22);		//中文验证码(2.0会有一个问题:msubstr有错误)		//1.修改function::msubstr		//2.加入字体ttf需要放入image同级目录之下		//扩展可以去类文件中查看//		Image::GBVerify();	}}?>


PageAction

<?php/** * ThinkPHP中的 */class PageAction extends CommonAction{	public function index(){		//导入page		import('ORG.Util.Page');		$user=M('User');		$count=$user->count();		$page=new Page($count, 3);		//修改提示信息		$page->setConfig('header', "个会员");		$page->setConfig('prev', "上一组");		$page->setConfig('next', "下一组");		$page->setConfig('first', "首页");		$page->setConfig('last', "尾页");				//定义主题样式(去看文档)//		$page->setConfig('theme', '<div>%%</div>');						$show=$page->show();				$list=$user->order('id desc')->limit($page->firstRow.','.$page->listRows)->select();				$this->assign('title','page演示');		$this->assign('alist',$list);		$this->assign('page',$show);		$this->display();	}	function check(){		$verify=$_SESSION['verify'];		if ($verify!=md5($_POST['verify'])) {			$this->error("验证码错误");		}	}	function next(){	}}?>


index

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title></title></head><body><form action="__URL__/check" method="post">	验证码:<input type="text" name="verify"/><img onclick="show(this)" src="__APP__/common/verify"/><br/>	<input type="submit" value="提交"/>	<!--{__NOTOKEN__}--></form><voList name="alist" id="vo">	<li>		<span>ID</span><!--{$vo['id']}-->		<span>用户名</span><!--{$vo['username']}-->		<span>IP</span><!--{$vo['createip']}-->	</li></voList><!--{$page}-->	<script type="text/javascript">		function show(obj){			obj.src="__APP__/common/verify?"+Math.random();		}	</script></body></html>