php - Yii comparing two attributes of different models -


in web application need compare attributes of 2 different models. have 2 models named "produceroffer" , "bookvegetable" . need compare 2 individual attributes . "booked_quantity" of "bookvegetable" table , "offered_qty" of "produceroffer" table . condition should check if "booked_quantity" less "offered_quantity". code wrote check condition

public function comparebookedquantity($booked_quantity,$params){     if(bookvegetable::model()->findbyattributes(array('booked_quantity'=>$booked_quantity ))> $this->offered_qty){          $this->adderror($attribute,'please enter quantity lesser offered quantity');       }     }  public function rules() {  array('offered_qty','comparebookedquantity'),    array(' vegetable_id, offered_qty, unit_cost, unit_delivery_cost', 'required'),         array(' offered_qty, unit_cost, unit_delivery_cost, booking_status, booked_by, available_days', 'numerical'),         array('user_id', 'length', 'max'=>11), array('offered_qty','comparebookedquantity'),   array('id,username,user_id, vegetable_id, unit_cost,book_vegetable_id, unit_delivery_cost, offered_date,offered_quantity,available_quantity,booking_status, booked_by, available_days', 'safe', 'on'=>'search'),     ); } 

but validation not happening @ all. how should correct error?

$booked_quantity - attribute - not attribute value. function must be:

public function comparebookedquantity($booked_quantity,$params){     $count = bookvegetable::model()->findbyattributes(array('booked_quantity'=>$this->$booked_quantity))->#field#;     if ($count > $this->offered_qty)         $this->adderror($booked_quantity,'please enter quantity lesser offered quantity'); } 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -