Noob Question about Dropdown List


I am new to Yii but I am amazed so far,

I am trying to make a drop down list with information from the customer model … I was able to display either their first name or last name but not the full name since they are separate attributes

<?php echo CHtml::dropDownList('cust_ref','', CHtml::listData(Customer::model()->findAll(),'cust_id','cust_lname')); ?>

Also I tried to add a private attribute to hold the full name on Customer.php but without luck!

please help!

You should use the "active" versions of the functions. That is, activeDropDownList() which takes as parameters the model and the property which the dropdown will be created for. See the API for more information.

will it enable me to concatenate the first and the last name?

Hm… Probably no. You will have to do it by yourself.

any thoughts on how to display a concatenated full name?

Try this

  1. In your customer model create an action that returns cust_id and cust_name.

Now the custom SQL in that model action concats cust_fname and cust_lname to make cust_name.

  1. Instead of findAll(), call the custom model action

Hope it helps!

You can define getFullName() method in your model class which returns the concatenated names. Then, you should be able to use listData to fetch 'fullName' and generate the options for dropDownList.

Thank you all,

I defined the method, but I am not able to access the attributes within the method.

I tried



but none of them work

define getFullName() method in model class

when access to


FullName without get prefix