如何在Yii2中以一种形式使用多个模型?
在我的创建操作中,我可以保存到agenda_fiscalizacao表中,但在更新中,当我尝试加载表单时收到此错误:
Call to a member function formName() on array
Run Code Online (Sandbox Code Playgroud)
public function actionUpdate($id)
{
$model = $this->findModel($id);
$modelAgenda = AgendaFiscalizacao::findAll(['fiscalizacao_id' => $id]);
if ($model->load(Yii::$app->request->post()) && Model::loadMultiple($modelAgenda, Yii::$app->request->post())) {
$valid = $model->validate();
$valid = $modelAgenda->validade() && $valid;
if ($valid) {
$model->save(false);
$modelAgenda->save(false);
return $this->redirect(['view', 'id' => $model->id]);
}
}
return $this->render('update', [
'model' => $model,
'modelAgenda' => $modelAgenda
]);
}
Run Code Online (Sandbox Code Playgroud)
<?= $form->field($modelAgenda, 'agenda_id')->checkboxList(Agenda::combo(), ['class' => 'checkbox']) ?>
<?= $form->field($model, 'bioma_id')->dropDownList(Bioma::combo(), ['prompt' => $prompt]) ?>
<?= $form->field($model, …Run Code Online (Sandbox Code Playgroud) First sorry for bad english!
I'm testing a RESTful API in YII2 and it's so easy to create, following the official guide. But by default (as far as I know) i can only pass the id as param to get a specific record.
For example, supposing that i have the following table called person:
id, name, age, gender, email, phone
In this case, i can only filter by id, like this: http://myserver/api/persons/1
我需要知道如何按其他字段过滤,例如年龄或性别。
我的控制器: …