I study Yii2, and I think the problem is obvious, but not for me.
When saving data through a form, an empty line is entered in the database. Used as QueryBuilder and ActiveRecord . Removed validation from the model did not help.
Information, oddly enough in general zero in the CIS. In addition to. documentation, and its translations, nothing at all. I reviewed a bunch of videos, but apart from repeating the same thing, I did not recognize anything new.
Crutches do not want to fence, and anyhow how to stick in the information there is not the right way.
Used a standard widget in the views:
<?php $form = ActiveForm::begin(); ?> <?= $form->field($model, 'name')->label('Имя') ?> <?= $form->field($model, 'category')->label('Категория') ?> <?= Html::submitButton('Отправить', ['class' => 'btn btn-primary']) ?> <?php ActiveForm::end(); ?> Model
namespace app\models; use yii\db\ActiveRecord; class Products extends ActiveRecord { public $name; public $category; public static function tableName() { return 'products'; } } The controller in the desired method:
$model = new Products(); if ($model->load(Yii::$app->request->post())) $model->save(); Without validation, without checks, just saving if the form is sent by post.
PS I already hate this framework, through its documentation, although it is huge, but the details are not explained. Spent about a week on this problem ... Help though with ideas, maybe the problem is not directly in the framework.
Массовое присвоение применяется только к так называемым безопасным атрибутам, которые являются атрибутами, перечисленными в scenarios()->По умолчанию scenarios() будет возвращать все сценарии и атрибуты найденные в rules()-> the author says that therules()masher -> therefore -> there are no safe attributes, since there are norules()-> therefore -> by default, the attributes will benull, whileload()will work (but idle) -> therefore -> that is why the model with confusing attributes (since they are allnull). - Roman Grinyov