think\Model::getAttr PHP Method

getAttr() public method

获取器 获取数据对象的值
public getAttr ( string $name ) : mixed
$name string 名称
return mixed
    public function getAttr($name)
    {
        try {
            $notFound = false;
            $value = $this->getData($name);
        } catch (InvalidArgumentException $e) {
            $notFound = true;
            $value = null;
        }
        // 检测属性获取器
        $method = 'get' . Loader::parseName($name, 1) . 'Attr';
        if (method_exists($this, $method)) {
            $value = $this->{$method}($value, $this->data);
        } elseif (isset($this->type[$name])) {
            // 类型转换
            $value = $this->readTransform($value, $this->type[$name]);
        } elseif ($notFound) {
            $method = Loader::parseName($name, 1);
            if (method_exists($this, $method) && !method_exists('\\think\\Model', $method)) {
                // 不存在该字段 获取关联数据
                $value = $this->relation()->getRelation($method);
                // 保存关联对象值
                $this->data[$name] = $value;
            } else {
                throw new InvalidArgumentException('property not exists:' . $this->class . '->' . $name);
            }
        }
        return $value;
    }