Codeigniter 类库参考
来源:互联网 发布:淘宝卖家投诉电话 编辑:程序博客网 时间:2024/06/08 06:22
购物车类:
$this->cart->insert(); //添加到购物车中
$this->cart->update(); //更新购物车中的项目
$this->cart->total(); //显示购物车的总计金额
$this->cart->total_items(); //显示购物车中总共的项目数量
$this->cart->contents(); //购物车中所有信息数组
$this->cart->has_options(rowid); //如果购物车中特定的包含选项信息,返回布尔值
$this->cart->product_options(rowid); //以数组的形式返回特定商品选项信息
***********************demo***************************
<?php $i=1; ?>
<?php foreach ($this->cart->contents() as $items):?>
<?php echo form_hidden($i.'[rowid]',$items['rowid']);?>
<?php if ($this->cart->has_options($items['rowid']) == TRUE):?>
<?php foreach ($this->cart->product_options($items['rowid']) as $option_name => $option_value):?>
<?php echo $option_name;?> : <?php echo $option_value;?>
<?php endforeach;?>
<?php endif;?>
<?php echo $this->cart->format_number($items['price']);?>
<?php echo $this->cart->format_number($items['subtotal']);?>
<?php $i++;?>
<?php endif;?>
<?php echo $this->cart->format_number($this->cart->total());?>
***********************demo end***************************
配置类:
主要配置文件: application/config/config.php
加载配置文件:系统会默认加载系统的配置文件,可手动建立自己的配置文件并手动加载。
$this->config->load('filename自定义配置文件名'); //手动加载
//第二个参数设置为ture,使每个配置文件的内容都存储在一个单独数组中
$this->config->load('filename',TRUE); // $this->config['filename']=$config
获取配置元素
$this->config->item('item name');
***********************demo*******************
$this->config->load('filename',TRUE);
$site_name=$this->config->item('site_name','filename');
OR
$filename=$this->config->item('filename');
$site_name=$filename['site_name'];
设置一项元素
$this->config->set_item('item_name','item_value');
辅助函数
$this->config->site_url(); //网站的URL
$this->config->system_url();
加密类
application/config/config.php
$config['encryption_key']='';
初始化:$this->load->library('encrypt');
执行数据加密:$this->encrypt->encode();
执行数据解密:$this->encrypt->decode();
文件上传类
需要表单属性 multipart
加载:$this->load->library('upload');
参数配置:
$config['upload_path']='./uploads';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size']='100';
$config['max_width']='1024';
$config['max_height']='768';
$this->load->library('upload',$config);
// $this->upload->initialize($config);
$this->upload->do_upload('文件域名称');
$this->upload->display_errors();
$this->upload->data();
表单验证类
加载:$this->load->library('form_validation');
// trim 去掉字符两端的空白
// required 必填项
// min_length[5] 最少字符数
// max_length[12] 最长字符数
// matches['password'] 匹配两次输入的密码
// md5 加密
// xss_clean 将用户名通过这个函数处理有害数据
$this->form_validateion->set_rules('username','USERNAME','trim|required|min_length[5]|max_length[12]|matches['password2']|MD5|xss_clean');
if($this->form_validation->run() == FALSE)
{
........
}else{
.......
}
图像处理类(调整大小,图像裁剪,图像旋转,添加水印)
载入:$this->load->library('image_lib');
基本参数设置:
$config['image_library']='gd2';
$config['source_image']='/path/to/image/mypic.jpg';
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = '75';
$config['height'] = '50';
$this->load->library('image_lib',$config);
$this->image_lib->resize();
创建一个备份和创建一个缩略图:
$this->image_lib->resize(); //创建图片并保留原图
$config['create_thumb'] = TRUE; //创建一个缩略图
$config['new_image'] = '/path/to/new_image.jpg'; //新图片存放路径
裁剪一张图片:$this->image-Lib->crop();
$config['image_library'] = "imagemagick";
$config['library_path'] ='/usr/x11R6/bin/';
$config['x_axis'] = '100';
$config['y_axis'] = '60';
$this->image_lib->initialize($config);
if( ! $this->image_lib->crop())
{
echo $this->image_lib->display_errors();
}
旋转图片:$this->image_lib->rotate();
$config['image_library'] = 'netpbm';
$config['library_path'] = '/usr/bin';
$config['source_image'] = '/path/to/image/mypic.jpg';
$config['rotation_angle'] = 'hor'; // hor--水平翻转 vrt--垂直翻转 90--逆时针旋转90
$this->image_lib->initialize($config);
if (! $this->image_lib->rotate())
{
echo $this->image_lib->display_errors();
}
水印图片:$this->image_lib->watermark();
$config['source_image'] = '/path/to/image/mypic.jpg';
$config['wm_text'] = '水印文字';
$config['wm_type'] = 'text';
$config['wm_font_path'] = './systme/fonts/texb.ttf';
$config['wm_font_color'] = 'ffffff';
$config['wm_vrt_alignment'] = 'bottom';
$config['wm_hor_alignment'] = 'center';
$config['wm_padding'] = '20';
$this->image_lib->initialize($config);
$this->image_lib->watermark();
输入类
$this->input->post();
$this->input->get();
$this->input->get_post();
$this->input->server();
$this->input->cookie();
$this->input->set_cookie();
装载类:
$this->load->library();
$this->load->view();
$this->load->model();
$this->load->database();
$this->load->vars($array);
$this->load->helper();
$this->load->file();
$this->load->language();
$this->load->config();
输出类
用给定的数据作为输出,比如数据导出EXCEL格式,放在最后一行代码
$this->output->set_output($data);
输出的数据保存起来,比如网站静态页
$string = $this->output->get_output();
设置HTTP协议头
$this->output->set_header();
分页类
$this->load->library('pagination');
$config['base_url'] = 'http://example.com/index.php/test/page/';
$config['total_rows'] = '200'; // 总记录
$config['per_page'] = '20';
$config['num_links'] ='2';
$this->pagination->initialize($config);
echo $this->pagination->create_links();
SESSION 类 system/config/config.php $config['sess_time_to_update']
$this->load->library('session');
$this->session->set_userdata($array);
$item = $this->session->userdata('item');
删除session数据
$this->session->unset_userdata('item');
$this->session->unset_userdata($array);
销毁Session
$this->session->sess_destory();
URI 类
$this->uri->segment();
$this->uri->segment(3,0); // 第二个参数设置默认值
$this->uri->uri_to_assoc(); //URL路径转换为数组形式
$this->uri->assoc_to_uri($array); //数组形式转换为URL路径
$this->uri->uri_string(); // 返回URL后半段地址
User-Agent 类
$this->load->library('user_agent');
$this->agent->is_browser('safari'); //浏览器
$this->agent->is_mobile('iphone'); //客户端
$this->agent->is_robot(); //机器人
$this->agent->version(); //版本
ZIP 编码类
$this->load->library('zip');
$this->zip->add_data($name,$array);
$this->zip->read_file($path,TRUE); //压缩某个文件
$this->zip->read_dir($path); //压缩某个文件夹
$this->zip->archive(); //把压缩文件写入服务器的某目录下
$this->zip->download(); //从服务器上下载一个zip文件
- Codeigniter 类库参考
- Codeigniter 类库加载
- php ci CodeIgniter快速参考图
- codeigniter使用pdo的参考配置
- CodeIgniter类库之Calendar Class
- CodeIgniter类库之Benchmarking Class
- CodeIgniter类库之Profiler Class
- CodeIgniter类库之Validation Class
- CodeIgniter 加密类分析
- CodeIgniter 装载类 分析
- CodeIgniter 分页类使用
- CodeIgniter 之数据库类
- codeigniter
- CodeIgniter
- codeigniter
- CodeIgniter
- CodeIgniter
- CodeIgniter
- URL安全问题(过滤器)
- 并行编译加快 VS C++ 项目的编译速度
- IOS开发百度地图API-用点生成路线,导航,气泡响应
- 获得SDCard路径,TF卡路径,OTG路径。
- How to add or remove a static ARP entry on Linux
- Codeigniter 类库参考
- Libcurl库支持SSL协议的编译方法
- or1200处理器中的特殊寄存器
- 各种map
- Iphone手机数据恢复软件
- ubuntu 光盘安装不能识别已有分区
- centos 打开firefox,出现:/usr/lib64/firefox/firefox: error while loading shared libraries: libstdc++.so.6
- C++primer plus第六版课后编程题答案7.10
- Silverlight中播放声音mp3文件