clevertech / YiiBooster

YiiBooster
BSD 2-Clause "Simplified" License
544 stars 305 forks source link

sortableAttribute as getter in CActiveDataProvider #946

Open cfuturesgroup opened 10 years ago

cfuturesgroup commented 10 years ago

I want use getter in CActiveRecord as sortableAttribute. For do this please change in TbExtendedGridView

    /**
     *### .getAttribute()
     *
     * Helper function to get an attribute from the data
     *
     * @param CActiveRecord $data
     * @param string $attribute the attribute to get
     *
     * @return mixed the attribute value null if none found
     */
    protected function getAttribute($data, $attribute)
    {
        if ($this->dataProvider instanceof CActiveDataProvider)
        {
            if ($data->hasAttribute($attribute))
            {
                return $data->{$attribute};
            }
            $method = 'get' . ucfirst($attribute);
            if (is_object($data) && method_exists($data, $method))
            {
                return call_user_func([$data, $method]);
            }
        }

        if ($this->dataProvider instanceof CArrayDataProvider || $this->dataProvider instanceof CSqlDataProvider) {
            if (is_object($data) && isset($data->{$attribute})) {
                return $data->{$attribute};
            }
                        if (isset($data[$attribute])) {
                return $data[$attribute];
            }
        }
        return null;
    }
amrbedair commented 10 years ago

what is this ... what do you need ...!