Thinkphp 3.0 of Parsefieldsmap related issues

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