Форма генерируется как:
Код: Выделить всё
<?= $form->field($model, 'blog_id'->'')->textInput() ?>
Код: Выделить всё
<?= $form->field($model, 'blog_id'->'')->textInput() ?>
Код: Выделить всё
<?= $form->field($model, 'blog_id')->dropDownList(
ArrayHelper::map($blog, 'id', 'name')
) ?>
Код: Выделить всё
<?= $this->render('_form', [
'model' => $model, 'blog'=>$blog,
]) ?>
Код: Выделить всё
public function actionView($id)
{
$blog= Blog::find()->all();
return $this->render('view', [
'model' => $this->findModel($id),
'blog' => $blog,
]);
}
public function actionCreate()
{
$model = new Comment();
$blog= Blog::find()->all();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}else {
return $this->render('create', [
'model' => $model,
'blog' => $blog,
]);
}
}
public function actionUpdate($id)
{
$model = $this->findModel($id);
$blog= Blog::find()->all();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('update', [
'model' => $model,
'blog' => $blog,
]);
}