php ci框架之创建mobel
来源:互联网 发布:linux 倒序查看文件 编辑:程序博客网 时间:2024/05/21 03:56
ci规定model的命名格式为XXX_model.php,model类名的命名格式为文件名第一个字母大写;如blog_model.php->class Blog_model extends CI_Model ;所有的model都继承自CI_Model;在model中如果配置文件autoload.php中没有配置$autoload['libraries'] = array('database');那么你就得先手动载入数据库类database;
public function __construct() { $this->load->database(); }
$this->db->get();运行选择查询语句并且返回结果集。可以获取一个表的全部数据 $this->db->select();允许你在SQL查询中写 SELECT 部分
$this->db->from();允许你编写查询中的FROM部分
$this->db->join();允许你编写查询中的JOIN部分
$this->db->where();允许你设置 WHERE 子句
$this->db->like();允许你生成 LIKE 子句等等;
具体可参考ci框架包解压出来的user_guide文件夹下的database/active_record.html
class Blog_model extends CI_Model
{
var $table = "blog";
/**
*获取所有分类
*
*/
function getAll()
{
return $this->db
->order_by("px")
->get($this->table)
->result_array();
}
/**
**获取一条分类
**
**/
function getOne($id)
{
return $this->db->from($this->table)
->where("id", $id)
->get()
->row_array();
}
/**
**添加分类
**
**/
function add()
{
$data = array(
'title' => $this->input->post('title'),
'cid' => $this->input->post('cid'),
'contents' => $this->input->post('contents'),
'px' => $this->input->post('px'),
);
$this->db->insert($this->table, $data);
}
/**
**修改分类
**
**/
function edit()
{
$data = array(
'title' => $this->input->post('title'),
'cid' => $this->input->post('cid'),
'contents' => $this->input->post('contents'),
'px' => $this->input->post('px'),
);
$id = $this->input->post('id');
$this->db->where('id', $id)->update($this->table, $data);
}
/**
**删除分类
**
**/
function del()
{
$id = $this->uri->segment(4);
$this->db->where('id',$id)->delete($this->table);
}
}
- php ci框架之创建mobel
- php ci框架之配置
- php ci框架之controller
- php ci框架之view
- PHP框架之CI:CodeIgniter
- PHP CI框架学习之路径访问
- CI框架 -- 核心文件 之 Benchmark.php
- PHP框架CI之源码解读
- php CI框架单元测试
- PHP CI 框架
- php CI框架入门
- CodeIgniter框架 CI PHP
- PHP CI框架配置
- CI框架源码完全分析之核心文件Codeigniter.php
- CI框架源码完全分析之入口文件index.php
- CI框架源码完全分析之核心文件Codeigniter.php
- CI框架源码分析之Session类Session.php
- CI框架源码解析一之入口文件index.php
- couchbase swappiness
- Spring整合JDBC实现简单的增删改续-实现基于RowMaper的查询
- 编码规范集锦
- 23种设计模式汇总
- css常见标签
- php ci框架之创建mobel
- sysconf()、pathconf()和fpathconf()函数
- 苹果进入健康领域,将如何面对隐私问题?
- 读取数据库并生成excel文件--PHPExcel
- 几个不错的深度学习教程
- JLINK、ULINK及ST-LINK
- iOS开发笔记之十四——Xcode 6.0.1下出现Thread 1: signal SIGPIPE问题的参考解决方案
- 数据挖掘10大算法的思维导图
- CXF学习-形参、返回值为javaBean,list或数组