亚洲最大看欧美片,亚洲图揄拍自拍另类图片,欧美精品v国产精品v呦,日本在线精品视频免费

  • 站長(zhǎng)資訊網(wǎng)
    最全最豐富的資訊網(wǎng)站

    解決TP5取不到Model的自定義字段問題

    thinkphp框架教程欄目將給大家介紹關(guān)于TP5取不到Model實(shí)例的自定義字段 type的問題,希望對(duì)需要的朋友有所幫助!

    解決TP5取不到Model的自定義字段問題

    thinkphp5 取不到Model實(shí)例的 自定義字段 type?

    $proxy->type 得到的結(jié)果是 []

    空數(shù)組

    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)建時(shí)間字段     protected $createTime = 'created_at';     // 更新時(shí)間字段     protected $updateTime = 'updated_at';      // 是否需要自動(dòng)寫入時(shí)間戳 如果設(shè)置為字符串 則表示時(shí)間字段的類型     protected $autoWriteTimestamp = 'datetime';      public function getTable($name = '')     {         return parent::getTable($name); // TODO: Change the autogenerated stub     }      /**      * type是父級(jí)thinkModel的屬性      * 不能直接$this->type      */     public function getType() {         return $this->data['type'];     }  // ... }

    查看父類 thinkModel

    thinkphp/library/think/Model.php

    解決TP5取不到Model的自定義字段問題

    thinkModel 定義了type字段 就不會(huì)走到 __get魔術(shù)方法

    假設(shè)走到__get方法

    解決TP5取不到Model的自定義字段問題

    接下來到getAttr方法

    解決TP5取不到Model的自定義字段問題

    然后是getData方法

    解決TP5取不到Model的自定義字段問題

    所以我在自定義的Model中添加方法取得type字段的值

        public function getType() {          return $this->data['type'];      }對(duì)于一些常見詞用來命名需要注意 比如 type, name, class...

    可以改名typeName, clazz

    贊(0)
    分享到: 更多 (0)
    網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)