小编jfl*_*dro的帖子

Yii2一种形式的多个模型

如何在Yii2中以一种形式使用多个模型?

我的情况: ER图

在我的创建操作中,我可以保存到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)

php yii2 yii2-model

6
推荐指数
1
解决办法
1万
查看次数

Filter by other fields on Yii2 RESTful API

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

我需要知道如何按其他字段过滤,例如年龄性别

我的控制器: …

php rest yii yii2

3
推荐指数
1
解决办法
2113
查看次数

标签 统计

php ×2

yii2 ×2

rest ×1

yii ×1

yii2-model ×1