public function checkRegion() { $user = Yii::app()->controller->user; if ($user->country_id == 1) { $province = Region::getRegionById($this->province_id); if ($province === null || $province->pid != $user->country_id) { $this->addError('province_id', Yii::t('common', 'Invalid province.')); return false; } $city = Region::getRegionById($this->city_id); if ($city === null || $city->pid != $this->province_id) { $this->addError('city_id', Yii::t('common', 'Invalid city.')); return false; } } }
public function checkRegion() { $region = Region::getRegionById($this->country_id); if ($region === null) { $this->addError('country_id', Yii::t('common', 'Invalid region.')); return false; } if ($this->country_id == 1) { if (!preg_match('{^[\\x{4e00}-\\x{9fc0}]+$}u', $this->local_name)) { $this->addError('local_name', Yii::t('common', 'Invalid local name.')); return false; } $province = Region::getRegionById($this->province_id); if ($province === null || $province->pid != $this->country_id) { $this->addError('province_id', Yii::t('common', 'Invalid province.')); return false; } $city = Region::getRegionById($this->city_id); if ($city === null || $city->pid != $this->province_id) { $this->addError('city_id', Yii::t('common', 'Invalid city.')); return false; } } }