Делаю так, это работает. Но как можно сделать массовое присвоение через ActiveRecord::attributes ?
controller
$blog = new Blog();
if($blog->load(Yii::$app->request->post())) {
$blog->addArticle();
}
model
class Blog extends ActiveRecord
public $form_title;
public $form_content;
public function rules() {
return [
[['title', 'content', 'status'], 'safe'],
[['form_title', 'form_content'], 'required'],
];
}
public function addArticle() {
// $this->attributes = $attributes;
$this->title = $this->form_title;
$this->content = $this->form_content;
$this->save();
}
view
<?php $form = ActiveForm::begin(['id' => 'my-form']); ?>
<?= $form->field($blog, 'form_title') ?>
<?= $form->field($blog, 'form_content')->textarea() ?>
<?= HTML::button('Сохранить', ['type' => 'submit']) ?>
<?php ActiveForm::end(); ?>