我有具有多步骤来定购商品等向导表单的表单...在Yii2中做一个向导表单的最佳方式是什么?
1)I可通过制表面板在一个视图编码,但我怎样才能移动到下一之前验证每个标签一。
2)有人给了我一些建议,根据“actionCreate”来做到这一点,但成功保存后,重定向到填充步骤的下一步,但会有额外的2-3表和模型.. ,但它是工作,看下面的例子:
public function actionShipping($id)
{
$model = new OrderDeliveryMethod();
$model->order_id = $id;
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['payment', 'id' => $model->id]);
} else {
return $this->render('shipping', [
'model' => $model,
]);
}
}
public function actionPayment($id)
{
$model = new OrderPaymentMethod();
$model->order_id = $id;
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['review', 'id' => $model->id]);
} else {
return $this->render('payment', [
'model' => $model,
]);
}
}
public function actionReview($id)
{
return $this->render('review', [
'model' => $this->findModel($id),
]);
}
是否有另一种方式来做到这一点?你可以给我一个例子吗?
哦谢谢,我认为使用场景是解决这个问题的好方法。再次感谢 :) – e236286