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: #008000;">//<span style="color: #008000;">如果setment不是3需要设置,默认为3 <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;">$sql = "SELECT * FROM <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;">上传文件信息 即可。 三、session1、开启 -> load -> library('session');默认已经开启,用上面的代码加载session库。 2、写入 = 'id' => 3,'name' => 'jim' -> session -> set_userdata("user",); -> 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', '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 '' (length=129) 'filename' => string '1436954914.3053.jpg' (length=19) <span style="color: #008000;">/ <span style="color: #0000ff;">echo <span style="color: #800080;">$cap['image']; 注意:需要手动创建存放验证码的文件夹,验证码图片会在超时后自动删除。 (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
