public function rules()
{
return array_merge(
parent::rules(),
[
[[‘shippingName’, ‘shippingAddress’, ‘shippingPhone’, ‘shippingProvince’, ‘shippingCity’, ‘shippingCounty’], ‘required’],
[[‘shippingProvince’, ‘shippingCity’, ‘shippingCounty’], ‘validateAddress’]
]
);
}
public function validateAddress($attribute, $params)
{
$address = $this->$attribute;
if (empty($address['name']) || empty($address['id'])) {
$this->addError($attribute, "");
return false;
}
return true;
}
这里要使用 this−>add