Answer the question
In order to leave comments, you need to log in
How to combine create form and edit form?
There is an Artist model. She has a relation Song;
Each artist has only one song.
The controller has two actions.
public function actionCreate()
{
$model = new Artist();
$this->render('update', array(
'model' => $model,
));
}
public function actionUpdate()
{
$id = Yii::app()->request->getQuery('id');
$model = Artist::model()->with('Song')->findByPk($id);
$this->render('update', array(
'model' => $model,
));
}
<?php $form->dropDownListGroup($model->song, 'name'); ?>
$model->song
. How to make it beautiful, so that for a new model this field would be empty?
Answer the question
In order to leave comments, you need to log in
<?php $form->dropDownList($model->song, 'name', CHtml::listData(Song::model()->findAll(), 'id', 'name')); ?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question