Home > Backend Development > PHP Tutorial > thinkphp problem consultation

thinkphp problem consultation

WBOY
Release: 2016-09-08 08:43:50
Original
1269 people have browsed it

Field filtering
If field data that does not exist in the data table is written, it will be filtered directly, for example:
$data['name'] = 'thinkphp';
$data['email'] = 'thinkphp@ gmail.com';
$data['test'] = 'test';
$User = M('User');
$User->data($data)->add();
Copy code
The test field does not exist, so it will be automatically filtered out when writing data.
In version 3.2.2 or above, if debugging mode is turned on, an exception will be thrown, prompting: Illegal data object: [test=>test]

The above is from the manual, debug is turned on, but no error is reported. I would have applied for other projects before. I reloaded the latest source code from the official website, but no error was reported. Especially when updating, the condition field was written incorrectly. I filtered it myself and updated all the data. It was very painful

Reply content:

Field filtering
If field data that does not exist in the data table is written, it will be filtered directly, for example:
$data['name'] = 'thinkphp';
$data['email'] = 'thinkphp@ gmail.com';
$data['test'] = 'test';
$User = M('User');
$User->data($data)->add();
Copy code
The test field does not exist, so it will be automatically filtered out when writing data.
In version 3.2.2 or above, if debugging mode is turned on, an exception will be thrown, prompting: Illegal data object: [test=>test]

The above is from the manual, debug is turned on, but no error is reported. I would have applied for other projects before. I reloaded the latest source code from the official website, but no error was reported. Especially when updating, the condition field was written incorrectly. I filtered it myself and updated all the data. It was very painful

I looked through the source code of TP3.2.3 and found that an error will only be reported when $this->options['strict'] is not empty. As for where to operate this options['strict'], I couldn't find it.

It feels like it’s a bug.
You can try to find it.

thinkphp_3.2.3_full/ThinkPHP/Library/Think/Model.class.php
Lines 267-277:

<code>foreach ($data as $key=>$val){
    if(!in_array($key,$fields,true)){
        // 如果字段不存在
        if(!empty($this->options['strict'])){
            // 只有在这个$this->options['strict']不为空的时候才抛异常。
            E(L('_DATA_TYPE_INVALID_').':['.$key.'=>'.$val.']');
        }
        // unset掉这个没用的字段
        unset($data[$key]);
    }elseif(is_scalar($val)) {
        $this->_parseType($data,$key);
    }
}</code>
Copy after login

If there are conditions, you can add another continuous operation of where()

ThinkPHPLibraryThinkModel.class.php There are two errors in it, one is a condition error, and the other is an insertion operation field error!
thinkphp problem consultation
There is no solution for the specific error. I compared it with 3.2.2 and changed it to the same conditions. There is no big problem.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template