Answer the question
In order to leave comments, you need to log in
How to load data into linked yii model?
Hello.
There is a model with connection:
/**
* This is the model class for table "{{%setting}}".
*
* @property int $id
* @property string $name
* @property int $status
*/
class Setting extends \yii\db\ActiveRecord
{
...
public function getAssign()
{
return $this->hasOne(SettingAssign::className(), ['setting_id' => 'id']);
}
...
}
/**
* This is the model class for table "{{%setting_assign}}".
*
* @property int $id
* @property int $setting_id
* @property string|null $lang_code
* @property int $value
*/
class SettingAssign extends \yii\db\ActiveRecord
{
//модель без изменений.
}
<?=$form->field($model, "assign[value]")->checkbox();?>
или так:
<?=$form->field($model->assign, "value")->checkbox();?>
public function actionIndex()
{
$model = Setting::find()->with('assign')->where(['name' => 'disconnected'])->one();
if( $model->load(\Yii::$app->request->post()) && $model->validate()){
$model->save();
}
return $this->render('_form', ['model' => $model]);
}
$model->assign->load($data);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question