Maison  >  Article  >  php教程  >  ThinkPHP学习笔记ThinkPHP的分页以及验证码的使用

ThinkPHP学习笔记ThinkPHP的分页以及验证码的使用

WBOY
WBOYoriginal
2016-06-13 10:54:401028parcourir

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', '

%%
');  

          

          

        $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

 

[php]  

 

 

 

 

 

 

 

 

    验证码:ThinkPHP学习笔记ThinkPHP的分页以及验证码的使用
 

     

     

 

 

   

  •  

            ID  

            用户名  

            IP  

       

  •  

     

     

       

            function show(obj){  

                obj.src="__APP__/common/verify?"+Math.random();  

            }  

         

     

     

     

    Déclaration:
    Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn