Answer the question
In order to leave comments, you need to log in
Yii how to make one form in Single Table Inheritance?
Hello everyone!) Again with stupid questions)) Following the example of https://sohabr.net/habr/post/274925/ I made my own models. I stopped in the actionCreate action, where we add new records to the database, as well as select new ones.
In actionCreate we have something like this:
public function actionCreate()
{
$model = new Сar();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('create', [
'model' => $model,
]);
}
$type = 'sport'
, the created model will not be changed to $model = new SportCar()
. role
Answer the question
In order to leave comments, you need to log in
public function actionCreate($type)
{
switch ($type){
case SportCar::TYPE:
$model = new SportCar();
break;
......
default:
$model = new Сar();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question