3
我们有表book
不同类型(Horror
,Travel
,History
)。
我们需要为这些书创建一个方法update
,但是对于每种书类型,我们需要显示不同类型的表单。
我们该如何做到这一点?
以下代码是否正确?
public function actionUpdate($id)
{
$model = $this->getType($id);
switch ($model->type){
case Book::TYPE_HORROR:
return $this->render('update_horror', [
'model' => $model
]);
break;
case Book::TYPE_TRAVEL:
return $this->render('update_travel', [
]);
break;
case Book::TYPE_HISTORY:
return $this->render('update_history', [
]);
}
throw new NotFoundHttpException;
}