thinkphp框架教程欄目將給大家介紹關于TP5取不到Model實例的自定義字段 type的問題,希望對需要的朋友有所幫助! thinkphp5 取不到Model實例的 自定義字段 type? 空數(shù)組 查看父類 thinkModel thinkphp/library/think/Model.php thinkModel 定義了type字段 就不會走到 __get魔術方法 假設走到__get方法 接下來到getAttr方法 然后是getData方法 所以我在自定義的Model中添加方法取得type字段的值 可以改名typeName, clazz
$proxy->type
得到的結(jié)果是 []
JdProxy.php
namespace appcrmmodel; use thinkModel; // use appadminmodelCommon 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(); } // 創(chuàng)建時間字段 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是父級thinkModel的屬性 * 不能直接$this->type */ public function getType() { return $this->data['type']; } // ... }
public function getType() { return $this->data['type']; }對于一些常見詞用來命名需要注意 比如 type, name, class...