Код: Выделить всё
<option value="c_00012">Ivan Moroz</option>
Сейчас такое отображение:
Код: Выделить всё
<option value="c_00011" selected="">c_00011</option>
Код: Выделить всё
<option value="c_00012">Ivan Moroz</option>
Код: Выделить всё
<option value="c_00011" selected="">c_00011</option>
нужно что бы в value пошел custom_id, которые мы сохранили в custom table и отображаться имя пользователя со связанной модели чтобы человек видел имя, фамилию пользователя. содержание таблиц customer (user_id, customer_id), data_user (user_id, first_name, last_name).
Controller:caHek2x писал(а): ↑2017.11.13, 00:43 мне кажется вы не ответили на вопрос ...
вы же создали между моделями связи ?
хотя нет, вы же создали для таблиц модели ?
вот если у вас есть модели и настроены между ними связи то что именно у вас не получается ? сделать для селекта массив ? покажите как вы пробовали ...
Код: Выделить всё
...
public function actionUpdate($id) // @todo tut ispravil nepravilnii vivod obratno v pole
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post())) {
if($model->save()) return $this->redirect(['view', 'id' => $model->id]);
else {
Yii::warning(serialize($model->getErrors()));
}
}
return $this->render('update', [
'model' => $model,
]);
}
...
Код: Выделить всё
echo $form->field($model, 'customer')->widget(Select2::classname(), [
'initValueText' => $cityDesc, // set the initial display text
'options' => ['placeholder' => Yii::t('users', 'INTER_USER_NAME')],
'pluginOptions' => [
'theme' => Select2::THEME_BOOTSTRAP,
'allowClear' => true,
'minimumInputLength' => 1,
'language' => [
'errorLoading' => new JsExpression("function () { return 'Waiting for results...'; }"),
],
'ajax' => [
'url' => 'search-customer-by-username',
'dataType' => 'json',
'data' => new JsExpression('function(params) { return {q:params.term}; }')
],
'escapeMarkup' => new JsExpression('function (markup) { return markup; }'),
'templateResult' => new JsExpression('function(city) { return city.text; }'),
'templateSelection' => new JsExpression('function (city) { return city.text; }'),
],
]);
Код: Выделить всё
public function getUsersArray()
{
$model = User::find()->all();
$array = [];
if ($model) {
foreach ($model as $user) {
$customers = Customers::find()->where(['user_id' => $user->id])->one();
if ($user->userData != null) {
$array[$customers->id] = ($user->userData->first_name || $user->userData->last_name) ? $user->userData->first_name . ' ' . $user->userData->last_name : $user->username;
} else {
$array[$customers->id] = $user->username;
}
}
}
return $array;
}