搜尋
首頁php框架ThinkPHP解決TP5取不到Model的自訂欄位問題

thinkphp框架教學欄位將介紹給大家關於TP5取不到Model實例的自訂欄位 type的問題,希望對需要的朋友有所幫助!

解決TP5取不到Model的自訂欄位問題

thinkphp5 取不到Model實例的 自訂欄位 type?

$proxy->type 得到的結果是[]

空數組

JdProxy.php

namespace app\crm\model;

use think\Model;
// use app\admin\model\Common as BaseModel;

class JdProxy extends Model {
    protected $table = '5kcrm_crm_district';

    protected $pk = 'id';

    protected $field = ['id',
        'type',
        'arm_acid',
        'province','city','district',
        'proxyname','manager','gradetype', 'has_updated'];

    protected function initialize() {
        parent::initialize();
    }

    // 创建时间字段
    protected $createTime = 'created_at';
    // 更新时间字段
    protected $updateTime = 'updated_at';

    // 是否需要自动写入时间戳 如果设置为字符串 则表示时间字段的类型
    protected $autoWriteTimestamp = 'datetime';

    public function getTable($name = '')
    {
        return parent::getTable($name); // TODO: Change the autogenerated stub
    }

    /**
     * type是父级\think\Model的属性
     * 不能直接$this->type
     */
    public function getType() {
        return $this->data['type'];
    }
 // ...
}

看父類別\think\Model 

thinkphp/library/think/Model.php

#\think\ Model 定義了type欄位就不會走到__get魔術方法

假設走到__get方法

接下來到getAttr方法

然後是getData方法

所以我在自訂的Model中新增方法取得type欄位的值

    public function getType() {
         return $this->data['type'];
     }对于一些常见词用来命名需要注意 比如 type, name, class...

可以改名typeName, clazz

#

以上是解決TP5取不到Model的自訂欄位問題的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文轉載於:csdn。如有侵權,請聯絡admin@php.cn刪除

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

強大的PHP整合開發環境

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

將Eclipse與SAP NetWeaver應用伺服器整合。

DVWA

DVWA

Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

VSCode Windows 64位元 下載

VSCode Windows 64位元 下載

微軟推出的免費、功能強大的一款IDE編輯器

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)