How do you call your own methods in a data model class in ThinkPHP5?

such as updating records, the official document is written like this. I now want to encapsulate this functionality in a class that inherits Model.

clipboard.png

clipboard.png

if you write this, you will report that there is no corresponding static method
self::allowField (true):: save ($companyInfo, ["id" = > $id]);

if you change self:: to $this- >, you will also get an error.

well, I don"t know how to write it. PHP Mengxin asks for advice.

Php
Aug.05,2021

function savedata($data,$id)
{
    return $this->allowField(['name','email'])->save($data,['id'=>$id]);
}

call

$res = $post->savedata(['name'=>'http://test','email'=>'testttttimg'],1);

execute sql statement

UPDATE `posts`  SET `name` = 'http://test' , `email` = 'testttttimg'  WHERE  `id` = 1

first take a look at the allowField method in Model.php in TP5

    /**
     * 
     * @access public
     * @param string|array $field  true
     * @return $this
     */
    public function allowField($field)
    {
        if (is_string($field)) {
            $field = explode(',', $field);
        }
        $this->field = $field;
        return $this;
    }

can you take a look at your model code? it feels like inheritance is not well written. Have you written the namespace correctly?

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b38a50-2c123.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b38a50-2c123.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?