yii2 的 ActiveRecord Class 规则问题
Issue with an ActiveRecord Class rules with yii2
昨天刚开始学Yii 2,有个问题不懂。它适用于这段代码,但如果我取消注释这两行
我有这个错误:
[...]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'] ,
];
}
}
我在发帖之前做了一些研究。
您列出规则的单个属性或属性数组,然后是验证器名称,然后是验证器参数,因此它应该是:
['name', 'string'],
['name', 'required'],
昨天刚开始学Yii 2,有个问题不懂。它适用于这段代码,但如果我取消注释这两行 我有这个错误:
[...]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'] ,
];
}
}
我在发帖之前做了一些研究。
您列出规则的单个属性或属性数组,然后是验证器名称,然后是验证器参数,因此它应该是:
['name', 'string'],
['name', 'required'],