ThinkPHP3.0 parseFieldsMap

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

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.