K
K
Ken Jee2016-08-29 22:53:44
Yii
Ken Jee, 2016-08-29 22:53:44

Why doesn't filling the model through model load work in Yii2?

<?php

namespace common\models;

use Yii;

class MyModel extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'mymodel';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['name'], 'required'],
            [['name'], 'string', 'max' => 70],
            [['name'], 'unique'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => 'Name',
        ];
    }
}

$model = new MyModel();
var_dump( $model->load( [ 'name' => 'Vasia' ] ) );

As a result, var_dump will display false... Well, of course, the model will not be filled. Why might the model fail to fill?

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
Никита, 2016-08-29
@Machez

Очень популярная ошибка.
или
$model->load(['name' => 'Vasia'], '');

A
Abdula Magomedov, 2016-08-29
@Avarskiy

1. Если указанное свойство не перечислено в правилах или в поведении.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question