欧美亚洲中文,在线国自产视频,欧洲一区在线观看视频,亚洲综合中文字幕在线观看

      1. <dfn id="rfwes"></dfn>
          <object id="rfwes"></object>
        1. 站長資訊網(wǎng)
          最全最豐富的資訊網(wǎng)站

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

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

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

          thinkphp5 取不到Model實例的 自定義字段 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)建時間字段     protected $createTime = 'created_at';     // 更新時間字段     protected $updateTime = 'updated_at';      // 是否需要自動寫入時間戳 如果設(shè)置為字符串 則表示時間字段的類型     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'];     }  // ... }

          查看父類 thinkModel

          thinkphp/library/think/Model.php

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

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

          假設(shè)走到__get方法

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

          接下來到getAttr方法

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

          然后是getData方法

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

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

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

          可以改名typeName, clazz

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