Answer the question
In order to leave comments, you need to log in
How to choose a more correct code solution?
Good day! The Search.php search model has a method for getting an array with usernames for further output as a dropdown list in the template
public function getDropDownData(): array
{
$data = [];
$query = self::find()->select('id')->distinct()->all();
foreach ($query as $user) {
$data[$user->id] = $user->getName();
}
return $data;
}
foreach ($query as $user) {
$data[$user->id] = $user->getName() . ' (' . $user->company->getName() . ')';
}
Answer the question
In order to leave comments, you need to log in
Make two methods.
1. User
names 2. User names + companies (sql query: join with the company table)
In the loop, only the formation of a value from the received data
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question