In ThinkPHP3.0, the parseFieldsMap field in the problem database is uid, and the name of the uname page form is id and nameModel code: PHPcodeprotected $ _ maparray (id & gt; uid, name & gt; uname,); A ThinkPHP 3.0 parseFieldsMap problem
The fields in the database are uid and uname.
The name of the page form is id and name
Model Code:
PHP code
protected $_map = array( 'id' => 'uid', 'name' => 'uname', );
Action code:
PHP 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!
------ 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 );
------ Solution --------------------
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)
PHP code
/** + ---------------------- * Process field ing + ---------------------- * @ access public + role * @ 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 ($ 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 ;}