The Parsefieldsmap Problem of thinkphp 3.0
The fields in the database are UID, uname
The name of the page form is ID and name, respectively
Model Code:
PHP Code
Protected $_map = Array ( ' id ' = ' uid ', ' name ' = ' uname ', );
Action Code:
PHP Code
$model = M (' Demo '); $list = select ($model); Print_r ($list); $list = $model-Parsefieldsmap ($list); Echo '
'; Print_r ($list);
The output is the same
's All
Array ([0] = = Array ([UID] = 1 [uname] + = Test))
Here's the problem:
According to the official word, Parsefieldsmap turned.
The final output of the $list should be
Array ([0] = = Array ([id] = 1 [name] + = Test))
That's right, huh?
I can't find it anywhere on the Internet.
Who knows, please do not hesitate to enlighten Ah!
------Solution--------------------
In fact, you should distinguish the M and D methods of m by not loading their own defined model files, and $_map is defined in your own created model file, so you should call: $list = d (' Demo '), Parsefieldsmap ($list);
------Solution--------------------
As defined by the Parsefieldsmap method:
He can only act on one-dimensional arrays, i.e.
Array ([UID] = 1 [uname] + = Test)
Into
Array ([id] = 1 [name] + = Test)
PHP code
/** +----------------------* processing field mappings +-- --------------------* @access public +----------------------* @param array $data Current Data * @param integer $ Type 0 Write 1 Read +----------------------* @return Array +----------------------*/Public Function PA Rsefieldsmap ($data, $type =1) {//Check field mapping if (!empty ($this->_map)) {foreach ($this->_map as $ Key=> $val) {if ($type ==1) {//Read if (Isset ($data [$val])) {$dat a[$key] = $data [$val]; Unset ($data [$val]); }}else{if (Isset ($data [$key])) {$data [$val] = $data [$key]; Unset ($data [$key]); }}}} return $data; }