Answer the question
In order to leave comments, you need to log in
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
$question = Question::find()->with('answers')->where(['id'=>$id])->one();
foreach($question->answers as $answerModel){
echo $this->render('_some_answer_form', ['model'=>$answerModel,'form'=>$form]);
}
public function getAnswers(){
return $this->hasMany(Questions::classname(),['question_id'=>'id']);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question