Answer the question
In order to leave comments, you need to log in
Why does ActiveRecord->save() save fields as null?
The controller has this method:
public function actionAdd () {
$req = json_decode(Yii::$app->request->getRawBody());
$task = new Tasks();
$task->name = $req->name;
$task->save();
}
class Tasks extends ActiveRecord {
public $name;
}
class m180710_143740_create_tasks_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->createTable('tasks', [
'id' => $this->primaryKey(),
'name' => $this->string(),
]);
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropTable('tasks');
}
}
Answer the question
In order to leave comments, you need to log in
1. If the ActiveRecord attributes are taken from the database, they do not need to be separately declared as class properties
2. Where are the validation rules in the model?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question