D
D
Dmitry Baibukhtin2014-08-20 21:01:51
Yii
Dmitry Baibukhtin, 2014-08-20 21:01:51

Why is $this partially hidden in Yii CActiveRecord?

Good evening. Please tell me, I need to get all the properties of the model inherited from CActiveRecord. Property getting code:

class MyModel extends CActiveRecord
{
    public $property1;
    public $property2;
    public $property3;
    
    public function getProperties()
    {
        foreach($this as $key => $value)
        {
            // ...
        }
    }

}

As a result, the contents of MyModel::_attributes (*CActiveRecord*) are displayed, and my $property1, $property2, $property3 are lost somewhere. Why is that? Can it be fixed?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Baibukhtin, 2014-08-20
@PiloTeZ

Problem solved. Instead of foreach($this...) I use foreach(get_object_vars('MyModel')...).
Just correctly gets the public properties I need

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question