コード例 #1
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return [['recordStatus', 'default', 'value' => static::RECORDSTATUS_USED], [['postcode', 'country_id'], 'required'], [['subdistrict_id', 'district_id', 'city_id', 'province_id'], 'safe'], [['recordStatus'], 'string'], [['postcode'], 'integer'], ['recordStatus', 'in', 'range' => [self::RECORDSTATUS_USED, self::RECORDSTATUS_DELETED]], ['country_id', 'exist', 'targetClass' => RgnCountry::className(), 'targetAttribute' => 'id', 'when' => function (RgnPostcode $model, $attribute) {
         $num = is_numeric($model->{$attribute});
         //$model->addError($attribute, "num: [{$num}]; val: [{$model->$attribute}];");
         return $num;
     }, 'message' => "Country doesn't exist."], ['province_id', 'exist', 'targetClass' => RgnProvince::className(), 'targetAttribute' => 'id', 'when' => function ($model, $attribute) {
         return is_numeric($model->{$attribute});
     }, 'message' => "Province doesn't exist."], ['city_id', 'exist', 'targetClass' => RgnCity::className(), 'targetAttribute' => 'id', 'when' => function ($model, $attribute) {
         return is_numeric($model->{$attribute});
     }, 'message' => "City doesn't exist."], ['district_id', 'exist', 'targetClass' => RgnDistrict::className(), 'targetAttribute' => 'id', 'when' => function ($model, $attribute) {
         return is_numeric($model->{$attribute});
     }, 'message' => "District doesn't exist."], ['subdistrict_id', 'exist', 'targetClass' => RgnSubdistrict::className(), 'targetAttribute' => 'id', 'when' => function ($model, $attribute) {
         return is_numeric($model->{$attribute});
     }, 'message' => "Subdistrict doesn't exist."]];
 }
コード例 #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getProvince()
 {
     return $this->hasOne(\common\models\RgnProvince::className(), ['id' => 'province_id']);
 }
コード例 #3
0
ファイル: RgnCity.php プロジェクト: fredyns/yii2-boilerplate
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return [['recordStatus', 'default', 'value' => static::RECORDSTATUS_USED], [['name', 'province_id'], 'required'], [['recordStatus'], 'string'], [['number'], 'string', 'max' => 32], [['name'], 'string', 'max' => 255], [['abbreviation'], 'string', 'max' => 64], ['recordStatus', 'in', 'range' => [self::RECORDSTATUS_USED, self::RECORDSTATUS_DELETED]], ['province_id', 'exist', 'targetClass' => RgnProvince::className(), 'targetAttribute' => 'id', 'when' => function ($model, $attribute) {
         return is_numeric($model->{$attribute});
     }, 'message' => "Province doesn't exist."]];
 }
コード例 #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRgnProvinces()
 {
     return $this->hasMany(\common\models\RgnProvince::className(), ['country_id' => 'id']);
 }