日期:2014-05-17 浏览次数:20474 次
protected $_map = array( 'id' => 'uid', 'name' => 'uname', );
$model = M('Demo'); $list = $model -> select(); print_r($list); $list = $model -> parseFieldsMap($list); echo '<br/><br/>'; print_r($list);
/** +---------------------- * 处理字段映射 +---------------------- * @access public +---------------------- * @param array $data 当前数据 * @param integer $type 类型 0 写入 1 读取 +---------------------- * @return array +---------------------- */ public function parseFieldsMap($data,$type=1) { // 检查字段映射 if(!empty($this->_map)) { foreach ($this->_map as $key=>$val){ if($type==1) { // 读取 if(isset($data[$val])) { $data[$key] = $data[$val]; unset($data[$val]); } }else{ if(isset($data[$key])) { $data[$val] = $data[$key]; unset($data[$key]); } } } } return $data; }