YiiBooster icon indicating copy to clipboard operation
YiiBooster copied to clipboard

sortableAttribute as getter in CActiveDataProvider

Open cfuturesgroup opened this issue 10 years ago • 1 comments

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;
    }

cfuturesgroup avatar Sep 10 '14 12:09 cfuturesgroup

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

amrbedair avatar Sep 12 '14 15:09 amrbedair