$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