E
E
Eugene2018-05-29 09:59:45
Yii
Eugene, 2018-05-29 09:59:45

How to send name value from DropDownlist to model instead of ID?

In general, when processing an order, depending on the department, a certain list of doctors is available.

<?= $form2->field($modelC, 'doctor')->dropDownList(ArrayHelper::map(\app\modules\admin\models\Doctors::find()->where(['category_id' => $model->category_id])->all(), 'id','name'),['style'=>'font-family: \'Exo 2\', sans-serif; color: #0f0f0f; font-size:17px'])->label('Врач')?>

Everything works fine and shows doctors only on the current order. But not the name of the doctor, but the id gets into the model. And the ID goes to the mail. How to make the name of the doctor come instead of id?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2018-05-29
@evgen9586

Good morning.
When generating a letter, get the doctor's full name by id and send it.
How do you send a letter, show.
How did you design the letter template?
ps
You get the doctor's id from the form. Using this id, you can get all the data about the doctor from the database, not only the name, but also some additional information. For example, the doctor's appointment hours are a month ahead.

public function getDoctor($id)
{
    return Doctor::find()->where('id=:id', [':id' => $id])->one();
}

public function contact($email)
    {
        if ($this->validate()) {
            Yii::$app->mailer->compose('order', [
                'date' => $this->date,
                'time' => $this->time,
                'doctor' => $this->getDoctor($this->doctor),
                'name' => $this->name
            ])
                ->setTo([$this->email])
                ->setFrom([$email =>$this->subject])
                ->setSubject('Подтвержение заказа')
                ->send();

            return true;
        }
        return false;
    }

And in the order view itself, you can already parse doctor into attributes
// подставьте свои значения вместо name, patronymic, surname
echo "Врач: " . $doctor->name . ' ' . $doctor->patronymic . ' ' . $doctor->surname

This is in a hurry, all this can be improved. It can be supplemented, for example, with a method that will collect full name or work schedule or something else interesting for the patient. All this should be written as a letter and formatted accordingly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question