kulturman
kulturman

Reputation: 13

Issue with an ActiveRecord Class rules with yii2

I just started learning Yii 2 yesterday and I have a problem that I don't understand. It's working well with this code, but if I uncomment the 2 lines I have this error:

[...]a rule must specify both attribute names and validator type.

<?php
namespace app\models\customer;
use yii\db\ActiveRecord;

class CustomerRecord extends ActiveRecord
{
    public static function tableName()
    {
        return 'customer';
    }

    public function rules()
    {
        return [
            //['name' => 'string'],
            //['name' => 'required'],
            ['birth_date', 'date', 'format' => 'd-m-Y'] ,
            ['birth_date', 'required'] ,
            ['notes', 'safe'] ,
        ];
    }
}

I made some researches before posting here.

Upvotes: 1

Views: 50

Answers (1)

Bizley
Bizley

Reputation: 18021

You list single attribute or array of attributes for the rule, then name of validator, then validator parameters so it should be:

['name', 'string'],
['name', 'required'],

Upvotes: 1

Related Questions