$table
$table :
专题model
<?php
/**
* 专题model
*/
class Topic_model extends CI_Model
{
private $table = 'topic';
public function __construct()
{
parent::__construct();
}
/**
* 添加专题
* */
public function addCate($topicData)
{
$this->db->insert($this->table,$topicData);
return $this->db->insert_id();
}
/**
* 编辑数据
* */
public function editCate($cateData,$cateId='')
{
foreach ($cateData as $k => $v)
{
$this->db->set($k, $v, FALSE);
}
$this->db->where('topicId', $cateId)->update( $this->table );
return $this->db->affected_rows();
}
/**
* 首页列表以及查询多条数据
* */
public function getTopicList($where=array(), $limit=10,$start=0)
{
$param = $this->_getWhere($where);
$this->db->where($param);
$this->db->order_by('termNum','desc')->limit($limit, $start);
return $this->db->get( $this->table )->result_array();
}
/**
* 查询总条数
* */
public function gettopicCount($condition='')
{
$where = $this->_getwhere($condition);
$this->db->where($where);
return $this->db->count_all_results($this->table);
}
/**
* 条件
* */
private function _getwhere($condition='')
{
$where = array();
if(!empty($condition['cateName']))
{
$where['cateName like'] = '%'.$condition['cateName'].'%';
}
if(isset($condition['menuId'])&&$condition['menuId']!='-1')
{
$where['menuId'] = $condition['menuId'];
}
if(!empty($condition['noCateId']))
{
$where['cateId !='] = $condition['noCateId'];
}
return $where;
}
/**
* 验证分类名称
* param int $cateId
* param var char $cateName
* */
public function checkUnique($cateName,$cateId)
{
return $this->db->get_where($this->table, array('cateName' => $cateName,'cateId !=' => $cateId))->num_rows();
}
/**
*获取单条数据
* */
public function getCateRow($cateId=0)
{
$this->db->where('topicId', $cateId);
$result = $this->db->get($this->table);
return $result->row_array();
}
/**
* 删除
* */
public function delete( $cateId=0 )
{
$this->db->where('topicId',$cateId);
return $this->db->delete($this->table);
}
}
/* End of file Goodscate_model.php */