时间:2021-07-01 10:21:17 帮助过:6人阅读
protected $_map = array( 'id' => 'uid', 'name' => 'uname', );
$model = M('Demo'); $list = $model -> select(); print_r($list); $list = $model -> parseFieldsMap($list); echo '
'; 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; }