Using multiple data columns in dropDownList


Is there a way to use multiple column data in a dropDownList?

This is what I have:

<?= $form->field($model, 'clients_id')->dropDownList(ArrayHelper::map(Clients::find()->all(), 'id', 'client_firstname'), ['style' => 'width:150px'])  ?>

This is what I want:

<?= $form->field($model, 'clients_id')->dropDownList(ArrayHelper::map(Clients::find()->all(), 'id', 'client_firstname'.' '.'client_lastname'), ['style' => 'width:150px'])  ?>


Yes you can do it using anonymous function or create function in model.

ArrayHelper::map(Clients::find()->all(), 'id', function ($client, $defaultValue) {

    return $client->firstname . ' ' . $client->lastname;


To get full name is common action, so i would prefer function in model:

class Clients extends ActiveRecord {

    public function getFullName() {

        return $this->firstname . ' ' . $this->lastname;



ArrayHelper::map(Clients::find()->all(), 'id', 'fullName');

Btw, models should be named in singular, e.g. Client

Awesome, thank you very much.