CI的分页和文件上传小实例

CI自带的内容

分页内容
文件上传

分页使用

public function test()
{
    $config['base_url'] = site_url('user/test');
    $config['total_rows'] = '200';
    $config['per_page'] = '20';


    // 转成整数,获取内容
    $offset = intval($this->uri->segment(3));
    // 在这里拼接sql语句,这里返回的是偏移量
    echo $offset;

    // 自定义内容
    $config['first_link'] = '首页';
    $config['last_link'] = '尾页';
    $config['next_link'] = '下一页';
    $config['prev_link'] = '上一页';

    $this->pagination->initialize($config);

    echo $this->pagination->create_links();

}
注意:__contruct方法写完之后,要添加parent::__contruct否则会找不到

文件上传

user.php

public function upload()
{
    echo "upload";
    $config['upload_path'] = './uploads/';
    $config['allowed_types'] = 'gif|jpg|png';

    $this->load->library('upload', $config);
    $bool = $this->upload->do_upload('pic');
    echo $bool;
    // $this->upload->initialize($config);
     var_dump($this->upload->data());
    $data = $this->upload->data();
    echo $data['file_name'];
}

uploadfile.php




    
    
    上传文件
    


    

你可能感兴趣的:(CI的分页和文件上传小实例)