ThinkPHP 3.0的parseFieldsMap问题
数据库里的字段是uid, uname
页面表单的name分别是id和name
Model代码:
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> protected $_map = array( 'id' => 'uid', 'name' => 'uname', );
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> $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; }<div class="clear"> </div>