S
S
Sergey Beloventsev2017-10-03 17:07:09
Yii
Sergey Beloventsev, 2017-10-03 17:07:09

How to properly concatenate an ArrayHelpers::map array?

there is a model User the user has the properties first_name, last_name, mible_name I need to get the id and full name of the user I do this

$user=ArrayHelper::map(User::find()->asArray()->all(),'id','last_name'." ".'first_name'.' '.'midle_name');

how do i get it right?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Kozhin, 2017-10-03
@Sergalas

1. Make a method in the model

public function getName()
{
  return $this->last_name . ' ' .$this->first_name . ' ' .$this->middle_name; 
}

2. Remove asArray() from the request
$users = ArrayHelper::map(User::find()->all(), 'id', 'name');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question