true), array('merchant_id, merchant_code', 'length', 'max'=>30), array('merchant_code_redeem_date, rel_merchant_name, rel_merchant_type', 'safe'), // The following rule is used by search(). // @todo Please remove those attributes that should not be searched. array('id, merchant_id, merchant_code, merchant_gentime, merchant_code_exp, merchant_code_redeem_date, rel_merchant_name, rel_merchant_type', 'safe', 'on'=>'search'), ); } /** * @return array relational rules. */ public function relations() { // NOTE: you may need to adjust the relation name and the related // class name for the relations automatically generated below. return array( 'merchantId' => array(self::BELONGS_TO, 'Merchant', 'merchant_id'), ); } /** * @return array customized attribute labels (name=>label) */ public function attributeLabels() { return array( 'id' => 'ID', 'merchant_id' => 'Merchant ID', 'merchant_code' => 'Merchant Code', 'merchant_gentime' => 'Merchant Generate Time', 'merchant_code_exp' => 'Merchant Code Expire', 'merchant_code_redeem_date' => 'Merchant Code Redeem Time', 'rel_merchant_name' => 'Merchant Name', 'rel_merchant_type' => 'Merchant Type', ); } /** * Retrieves a list of models based on the current search/filter conditions. * * Typical usecase: * - Initialize the model fields with values from filter form. * - Execute this method to get CActiveDataProvider instance which will filter * models according to data in model fields. * - Pass data provider to CGridView, CListView or any similar widget. * * @return CActiveDataProvider the data provider that can return the models * based on the search/filter conditions. */ public function search() { // @todo Please modify the following code to remove attributes that should not be searched. $criteria=new CDbCriteria; $criteria->compare('id',$this->id); $criteria->compare('merchant_id',$this->merchant_id,true); $criteria->compare('merchant_code',$this->merchant_code,true); $criteria->compare('merchant_gentime',$this->merchant_gentime,true); $criteria->compare('merchant_code_exp',$this->merchant_code_exp); $criteria->compare('merchant_code_redeem_date',$this->merchant_code_redeem_date,true); $criteria->compare('rel_merchant_name',$this->rel_merchant_name,true); $criteria->compare('rel_merchant_type',$this->rel_merchant_type,true); return new CActiveDataProvider($this, array( 'criteria'=>$criteria, )); } protected function afterFind() { $dataRel = Merchant::model()->findByAttributes(array('merchant_id' =>$this->merchant_id)); if(is_null($this->merchant_code_redeem_date) || $this->merchant_code_redeem_date = '') { $this->merchant_code_redeem_date = '-'; } else { $this->merchant_code_redeem_date = $this->merchant_code_redeem_date; } // $this->rel_merchant_name = $dataRel['merchant_name']; // $this->rel_merchant_type = $dataRel['merchant_type']; $this->attributes['rel_merchant_name'] = 'aaaaaaa'; $this->attributes['rel_merchant_type'] = 'bbbbbbb'; parent::afterFind(); } /** * Returns the static model of the specified AR class. * Please note that you should have this exact method in all your CActiveRecord descendants! * @param string $className active record class name. * @return MerchantBatchCode the static model class */ public static function model($className=__CLASS__) { return parent::model($className); } }