The fields in the database for parseFieldsMap of ThinkPHP3.0 are uid and uname.
The name of the page form is id and name
Model Code:
protected $_map = array('id' => 'uid','name' => 'uname',);
Action code:
$model = M('Demo');$list = $model -> select();print_r($list);$list = $model -> parseFieldsMap($list);echo '
';print_r($list);
The output results are the same.
All
Array ([0] => Array ([uid] => 1 [uname] => test ))
The problem is as follows:
According to the official statement, after parseFieldsMap is transferred
The final output $ list should be
Array ([0] => Array ([id] => 1 [name] => test ))
That's right?
Not found anywhere on the Internet
If anyone knows, please kindly advise me!
Reply to discussion (solution)
In fact, the M method that you should distinguish between M and D is not to load the model file defined by yourself, while $ _ map is defined in the model file created by yourself, therefore, you should call $ list = D ('demo')-> parseFieldsMap ($ list );
In fact, the M method that you should distinguish between M and D is not to load the model file defined by yourself, while $ _ map is defined in the model file created by yourself, therefore, you should call $ list = D ('demo')-> parseFieldsMap ($ list );
M is written in the official document, and I have tried D, which is useless ~
We can see from the definition of parseFieldsMap:
It can only act on one-dimensional arrays, that is
Array ([uid] => 1 [uname] => test)
Change
Array ([id] => 1 [name] => test)
/** + Processing * field ing + ---------------------------------------------------------- * @ access public + ---------------------------------------------------------- * @ param array $ data current data * @ param integer $ type 0 write 1 READ + reply ----------------------------------------------------------*@ return array + ---------------------------------------------------- ------ */Public function parseFieldsMap ($ data, $ type = 1) {// Check the field ing if (! Empty ($ this-> _ map) {foreach ($ this-> _ map as $ key => $ val) {if ($ type = 1) {// read 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 ;}
/*** Process field ing * @ access public * @ param array $ data current data * @ param integer $ type 0 write 1 read * @ return array */public function parseFieldsMap ($ data, $ type = 1) {// Check the field ing if (! Empty ($ this-> _ map) {foreach ($ data as $ dkey => $ dval) {if (is_array ($ dval )) {$ data [$ dkey] = self: parseFieldsMap ($ dval, $ type);} else {foreach ($ this-> _ map as $ key => $ val) {if ($ type = 1) {// read 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 ;}} /* foreach ($ this-> _ map as $ key => $ val) {if ($ type = 1) {// read 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 ;}