ThinkPHP3.0 parseFieldsMap problems

Source: Internet
Author: User
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 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.