Combine Two Models Objects In One Cdetailview

Dear all,

I have a model Adress and a model Person. Each person has an adress now I want to display the person and adress data in one CDetailView.

What I’ve tried is to use array_merge($person->attributes, $person->adress->attributes) but then I get the problem that one attribute of person is salutation which is stored with 0 => Mr. and 1 => Mrs. in the database. Therefore I’ve implemented a getSalutation-method which converts this database value to a readalbe value.

The $model->attributes oder $model->getAttributes() don’t call this special getSalutation() so what can I do?


Hi Gerrit, welcome to the forum.

Hmm, why do you have to merge $person->attributes and $person->address->attributes?

I’ve never done that when using CDetailView.

your question is not clear , can you share some code, do u have the relationship b/w person and address if so, then you can solve your problem using relationship But Please Clarify your questions.

and whey your are showing data in CDetailView b/c i assume there may be one-many relationship! one person have many addresses!!

Thank you, yes there is a relationship so I could update my CDetailView-config to show the field adress.street. Now it works.

But there is an additional question: I’ve implemented a method to translate the salutation to a readable value in $person->getSalutation();

How can I use the getSalutation-method in CDetailView-config?

<?php $this->widget('zii.widgets.CDetailView', array(




		'salutation', // <-- How to use getSalutation here?









)); ?>

define a method for it in your model and return its readible value something like: