nomar
(Rzoellner)
June 22, 2009, 1:56pm
1
Hi there,
is it possible to retrieve data from relational objects via the CHtml::active* Methods?
I tried
CHtml($myModel, 'relation.property')
which resulted in an error.
Looking at the code of CActiveRecord it seems not to be possible? What would be the correct approach here?
Writing this, it comes to my mind that
CHtml($myModel->relation, 'property')
could work. But I don't like this, because I need to change all occurrences of 'relation' when this changes or a good refactoring tool.
The other thing I'd like to know is where to put business logic especially when this logic operates on multiple ActiveRecords.
Thanks,
Ramon
qiang
(Qiang Xue)
June 22, 2009, 2:42pm
2
What do you mean by "CHtml($myModel, 'relation.property')"? This is not a valid PHP exp​ression anyway because CHtml is a class.
nomar
(Rzoellner)
June 22, 2009, 3:26pm
3
Sorry, I was not paying enough attention to the code.
What I meant was
CHtml::activeTextField($myModel, 'relation.property');
where 'relation' is a relational property of myModel like an address for a person.
So one could translate this to
CHtml::activeTextField($person, 'address.street');
qiang
(Qiang Xue)
June 24, 2009, 5:43pm
4
This is not supported, and I'm afraid we won't support it in future because it introduces too much code complexity, lowers performance, without much benefit.
As a workaround, you could pass 'address'=>$person->address to the view and therefore be able to use
CHtml::activeTextField($address, 'street');