[英]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.我昨天刚开始学习 Yii 2,遇到一个我不明白的问题。 It's working well with this code, but if I uncomment the 2 lines I have this error:
它与此代码运行良好,但如果我取消注释 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'] ,
];
}
}
I made some researches before posting here.我在这里发帖之前做了一些研究。
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'],
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.