PHP   发布时间:2019-11-21  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了CodeIgniter学习笔记五:分页,文件上传,session,验证码大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

一、分页

示例代码:

-> load -> library('pagination');

<span style="color: #800080;">$controller = <span style="color: #800080;">$this->router-><span style="color: #000000;">fetch_class();
<span style="color: #800080;">$action = <span style="color: #800080;">$this->router-><span style="color: #000000;">fetch_method();

<span style="color: #008000;">//<span style="color: #008000;">每页显示10条数据,共有101条数据
<span style="color: #800080;">$config['base_url'] = site_url("<span style="color: #800080;">$controller/<span style="color: #800080;">$action"<span style="color: #000000;">);
<span style="color: #800080;">$config['@R_957_10586@l_rows'] = 101<span style="color: #000000;">;
<span style="color: #800080;">$config['per_page'] = 10<span style="color: #000000;">;
<span style="color: #800080;">$config['first_link'] = "首页"<span style="color: #000000;">;
<span style="color: #800080;">$config['prev_link'] = "上一页"<span style="color: #000000;">;
<span style="color: #800080;">$config['next_link'] = "下一页"<span style="color: #000000;">;
<span style="color: #800080;">$config['last_link'] = "最后一页"<span style="color: #000000;">;

<span style="color: #008000;">//<span style="color: #008000;">如果setment不是3需要设置,默认为3
<span style="color: #800080;">$config['uri_segment'] = 3<span style="color: #000000;">;

<span style="color: #800080;">$this -> pagination -> initialize(<span style="color: #800080;">$config<span style="color: #000000;">);

<span style="color: #008000;">//<span style="color: #008000;">偏移量
<span style="color: #800080;">$offset = <span style="color: #008080;">intval(<span style="color: #800080;">$this -> uri -> segment(3<span style="color: #000000;">));

<span style="color: #800080;">$sql = "SELECT * FROM TEST LIMIT <span style="color: #800080;">$offset," . <span style="color: #800080;">$config['per_page'<span style="color: #000000;">];

<span style="color: #800080;">$pager = <span style="color: #800080;">$this -> pagination -><span style="color: #000000;"> create_links();

<span style="color: #800080;">$this -> load -> view('article/index',<span style="color: #0000ff;">array('pager' => <span style="color: #800080;">$pager,'sql' => <span style="color: #800080;">$sql));

需要注意的是,如果配置了url中隐藏index.php,在site_url中生成的路径中默认还是有index.php,需要在application/config/config.php中改成如下配置:

['index_page'] = '';

即可。

二、文件上传

 示例代码:

['upload_path'] = './uploads/'['allowed_types'] = "gif|png|jpg|jpeg"['max_size'] = 512['file_name'] = );

<span style="color: #800080;">$this -> load -> library('upload',<span style="color: #800080;">$config<span style="color: #000000;">);
<span style="color: #008000;">//<span style="color: #008000;">pic为input type=file的name
<span style="color: #800080;">$this -> upload ->do_upload('pic'<span style="color: #000000;">);

<span style="color: #008000;">//<span style="color: #008000;">上传文件信息
<span style="color: #800080;">$uploadInfo = <span style="color: #800080;">$this -> upload -><span style="color: #000000;"> data();
<span style="color: #008080;">var_dump(<span style="color: #800080;">$uploadInfo<span style="color: #000000;">);
<span style="color: #008000;">/<span style="color: #008000;">
array (size=14)
'file_name' => String '55a61d04e96f4.jpg' (length=17)
'file_type' => String 'image/jpeg' (length=10)
'file_path' => String 'E:/wamp/www/citest/uploads/' (length=27)
'full_path' => String 'E:/wamp/www/citest/uploads/55a61d04e96f4.jpg' (length=44)
'raw_name' => String '55a61d04e96f4' (length=13)
'orig_name' => String '55a61d04e96f4.jpg' (length=17)
'client_name' => String 'hk.jpg' (length=6)
'file_ext' => String '.jpg' (length=4)
'file_size' => float 125.09
'is_image' => Boolean true
'image_width' => int 675
'image_height' => int 900
'image_type' => String 'jpeg' (length=4)
'image_size_str' => String 'width="675" height="900"' (length=24)
<span style="color: #008000;">
/

即可。

三、session

1、开启

-> load -> library('session');

默认已经开启,用上面的代码加载session库。

2、写入

= 'id' => 3,'name' => 'jim'); -> session -> set_userdata("user",);

5;">3、读取

-> session -> userdata('user')

注:建议在 application/config/config.php 中配置加密key:

['encryption_key'] = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx';

四、验证码

例:

->load->Helper('captcha'); = 'Random word', 'img_path' => './captcha/','img_url' => base_url() . 'captcha/', './path/to/fonts/texb.ttf', 'img_width' => '200','img_height' => 80,'expiration' => 60,'word_length' => 10,'font_size' => 26,'img_id' => 'ImagEID','pool' => '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRstuVWXYZ',BACkground and border,black text and red grid 'colors' => 'BACkground' => (255,255,255),'border' => (255,'text' => (0,0),'grid' => (255,40,40);

<span style="color: #800080;">$cap = create_captcha(<span style="color: #800080;">$vals<span style="color: #000000;">);
<span style="color: #008080;">var_dump(<span style="color: #800080;">$cap<span style="color: #000000;">);
<span style="color: #008000;">/<span style="color: #008000;">
array (size=4)
'word' => String 'hFan3NM4xB' (length=10)
'time' => float 1436954914.3053
'image' => String '

CodeIgniter学习笔记五:分页,文件上传,session,验证码

' (length=129)
'filename' => String '1436954914.3053.jpg' (length=19)
<span style="color: #008000;">/

<span style="color: #0000ff;">echo
<span style="color: #800080;">$cap
['image'];

注意:需要手动创建存放验证码的文件夹,验证码图片会在超时后自动删除。

大佬总结

以上是大佬教程为你收集整理的CodeIgniter学习笔记五:分页,文件上传,session,验证码全部内容,希望文章能够帮你解决CodeIgniter学习笔记五:分页,文件上传,session,验证码所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。