其他分享
首页 > 其他分享> > tp验证码、分页

tp验证码、分页

作者:互联网

TP框架中自带了验证码类
位置:Think/verify.class.php
ttfs:可用字体

在LoginController控制器中创建生存验证码
public function verifyImg(){
$config=array(
'imageW'=>120,
'imageH'=>40,
'fontSize'=>15,
'fontttf'=>'4.ttf'
);
$obj=new\Think\Verify($config);
$obj->entry();
}

在LoginController控制器中判断验证码是否正确并且判断登陆是否成功
public function check(){
$uid=$_POST['uid'];
$pwd=$_POST['pwd'];

$list=M('user')->where("username = '$uid'")->select();

if($list[0]['password']==$pwd && $pwd != ""){
// $this->redirect('Index/index','',3,'登录成功');
session('user',$list[0]);
$this->success('成功',U('Index/index'));
}else{
$this->redirect();
}
}
$_FILE[名字][]用来接收文件的信息
第二维的字段:
name
size
error
type
tmp_name

move_uploaded_file(临时文件,目标文件)
ThinkPHP自带了文件上传的类。位置:Think/Upload.class.php

缩略图类存放的位置 Think\Image.class.php

数据分页
Think\page.class.php用于分页
public function __construct($totalRows, $listRows=20, $parameter = array()) {
C('VAR_PAGE') && $this->p = C('VAR_PAGE'); //设置分页参数名称
/* 基础设置 */
$this->totalRows = $totalRows; //设置总记录数
$this->listRows = $listRows; //设置每页显示行数
$this->parameter = empty($parameter) ? $_GET : $parameter;
$this->nowPage = empty($_GET[$this->p]) ? 1 : intval($_GET[$this->p]);
$this->nowPage = $this->nowPage>0 ? $this->nowPage : 1;
$this->firstRow = $this->listRows * ($this->nowPage - 1);
}
分页自定义样式
public function show() {
if(0 == $this->totalRows) return '';

/* 生成URL */
$this->parameter[$this->p] = '[PAGE]';
$this->url = U(ACTION_NAME, $this->parameter);
/* 计算分页信息 */
$this->totalPages = ceil($this->totalRows / $this->listRows); //总页数
if(!empty($this->totalPages) && $this->nowPage > $this->totalPages) {
$this->nowPage = $this->totalPages;
}

/* 计算分页临时变量 */
$now_cool_page = $this->rollPage/2;
$now_cool_page_ceil = ceil($now_cool_page);
$this->lastSuffix && $this->config['last'] = $this->totalPages;

//上一页
$up_row = $this->nowPage - 1;
$up_page = $up_row > 0 ? '<a class="prev" href="' . $this->url($up_row) . '">' . $this->config['prev'] . '</a>' : '';

//下一页
$down_row = $this->nowPage + 1;
$down_page = ($down_row <= $this->totalPages) ? '<a class="next" href="' . $this->url($down_row) . '">' . $this->config['next'] . '</a>' : '';

//第一页
$the_first = '';
if($this->totalPages > $this->rollPage && ($this->nowPage - $now_cool_page) >= 1){
$the_first = '<a class="first" href="' . $this->url(1) . '">' . $this->config['first'] . '</a>';
}

//最后一页
$the_end = '';
if($this->totalPages > $this->rollPage && ($this->nowPage + $now_cool_page) < $this->totalPages){
$the_end = '<a class="end" href="' . $this->url($this->totalPages) . '">' . $this->config['last'] . '</a>';
}

//数字连接
$link_page = "";
for($i = 1; $i <= $this->rollPage; $i++){
if(($this->nowPage - $now_cool_page) <= 0 ){
$page = $i;
}elseif(($this->nowPage + $now_cool_page - 1) >= $this->totalPages){
$page = $this->totalPages - $this->rollPage + $i;
}else{
$page = $this->nowPage - $now_cool_page_ceil + $i;
}
if($page > 0 && $page != $this->nowPage){

if($page <= $this->totalPages){
$link_page .= '<a class="num" href="' . $this->url($page) . '">' . $page . '</a>';
}else{
break;
}
}else{
if($page > 0 && $this->totalPages != 1){
$link_page .= '<span class="current">' . $page . '</span>';
}
}
}

 

标签:&&,分页,验证码,tp,nowPage,totalPages,now,page,cool
来源: https://www.cnblogs.com/wjwap/p/10538486.html