enoc22
(Hauver 1)
November 29, 2011, 9:31pm
1
Hi All,
I have two models that are related(customer and commissions).
In my customer model i have a virtual attribute ‘fullname’
class Customer extends CActiveRecord
{
.....
public function getFullName(){
return $this->first_name . ' ' . $this->last_name;
}
.....
}
My question is: Is it possible to use Customer’s fullname attribute in Commissons to create another virtual attribute?
I’ve tried the following but i get an error ‘Trying to get property of non-object ’
class Commissions extends CActiveRecord
{
.....
public function getCustomerName(){
return $this->customer->fullname;
}
.....
}
Let me know
Thanks
Oliver
phtamas
(Phtamas)
November 29, 2011, 10:28pm
2
public function getCustomerName(){
return $this->customer instanceof Customer ? $this->customer->fullname : null;
}
enoc22
(Hauver 1)
November 29, 2011, 11:07pm
3
@Phtamas Thanks for the reply!! i tried your suggestion in my commissions model and i got the following error "Property "Commissions.fullname" is not defined. "
This is what i have in my view file:
array(
'name'=>'fullname',
'header'=>'Customer',
),
Any Ideas?
Thanks again!
Oliver
kokomo
(Mwerlberger85)
November 29, 2011, 11:17pm
4
Following the wiki article Understanding Virtual Attributes and get/set methods should solve your problem
enoc22
(Hauver 1)
November 30, 2011, 12:06am
5
Thanks Kokomo! I was able to figure it out. Phtamas Suggestion did work, i had to change the attribute name in my view file.
Thanks million guys!!
Oliver