标签:code uri span param ida nts return att ali
class BaseModel extends Model { public function rules() { return [ [‘obj‘, ContentSecurityValidator::class], ]; } public function exec() { if (!$this->validate()) { return [ ‘errors‘ => $this->errors ]; } } public function attributeLabels() { return [ ‘obj‘ => ‘标签‘, ]; } } /** * 自定义验证类 */ class BaseValidator extends Validator { /** * 必须要实现该方法 * @param \yii\base\Model $model * @param string $attribute 参数名 * @return bool */ public function validateAttribute($model, $attribute) { $attributeValue = $model->$attribute;//获取$model里面的参数的值 $attributes = $model->attributes;//获取model里面的参数数组 $attributeLabels = $model->attributeLabels();//获取model里面的已经设置好参数对应标签 } }
class BaseModel extends Model { public function rules() { return [ [‘obj‘, ‘validate‘], ]; } public function exec() { if (!$this->validate()) { return [ ‘errors‘ => $this->errors ]; } } public function attributeLabels() { return [ ‘obj‘ => ‘标签‘, ]; } /** * 自定义方法 */ public function validate($attribute) { $attributeValue = $this->$attribute;//获取$model里面的参数的值 $attributes = $this->attributes;//获取model里面的参数数组 $attributeLabels = $this->attributeLabels();//获取model里面的已经设置好参数对应标签 } }
标签:code uri span param ida nts return att ali
原文地址:https://www.cnblogs.com/fatRabbit-/p/11471032.html