V
V
Vitaly Khvan2018-07-11 09:22:42
Yii
Vitaly Khvan, 2018-07-11 09:22:42

Complex shapes in YII2?

Good afternoon, dear, for a week now I have been rummaging in search of solutions to push dynamic addition of models into 1 form, depending on the user's actions. For example, there are 2 tables:
Question
id - autoincrement (int - 11)
body - string (varchar - 255)
created_at - timestamp (behaviorCreate)
updated_at - timestamp
Answer
id - autoincrement (int - 11)
question_id = int - 11
suffix - string ( varchar - 1)
body - string (text)
is_correct - tinyint - 1
created_at
updated_at one Question can have many Answers
in the implementation of Django I can create a relay out of the box and, when added to the admin panel, calmly call the dynamic formation of fields to fill in the answer when creating Question
Is there an implementation example in Yii2 or a widget that more or less (without dancing with a tambourine) copes with this task?
And if anyone knows, what is the term for this action?
PS There is no example code yet, because. of all this, I implemented only models, and when transferring the admin logic from django to Yii2, I got stuck on this issue.
Thank you all in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mykola, 2018-07-11
@iSensetivity

https://github.com/unclead/yii2-multiple-input is it?

M
Maxim Timofeev, 2018-07-11
@webinar

$question = Question::find()->with('answers')->where(['id'=>$id])->one();
foreach($question->answers as $answerModel){
   echo $this->render('_some_answer_form', ['model'=>$answerModel,'form'=>$form]);
}

something like this, while you need to create an answers connection in the model beforehand
public function getAnswers(){
   return $this->hasMany(Questions::classname(),['question_id'=>'id']);
}

You didn’t explain this, it’s most likely js, which either hides and shows or knocks ajax on the server and receives some data, which is then inserted into the form.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question