E
E
enchikiben2012-10-13 22:21:51
Yii
enchikiben, 2012-10-13 22:21:51

Preserving Properties When Searching

Good evening! Is it possible to save the value of certain model properties when calling the find method and all its consequences.
For example:

$model = R::model();
$model->a = '123'// a это не столбец БД это свойство модели
$model->findAll();

after findAll property, a is nullified, how is it possible to save it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2012-10-13
Protko @Fesor

Well, first you need to understand what happens when you call the model() method and the findAll() method.
If we abstract from the specific implementation, then the model () method will return you a "repository" of records, and findAll () - a collection of records. This means that all these objects are different instances, and all properties for them have their own values. The only way with your approach where the property is initialized before findAll() is with static properties. Then one such property will be common to all instances. But this is not good.
In any case, you have events. You can write the afterFind() method in the model and see everything you want there. You can do this externally by handling such an event through a behavior or simply by subscribing your handler to this event.

I
Ilya Plotnikov, 2012-10-14
@ilyaplot

MyModel extends CModel and implement the desired functionality. I don't get it, what's the catch?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question