php - Unique filed according to admin id in yii -
i using yii framework , have 3 fields in table named table_details , fields table_number,seats , admin_id.i want enter unique table_number each admin_id.if use unique validation field table_number,then insert table_number once in table want insert table_number uniquely each admin_id.
you can define own rule. i.e.
public function rules() { return array( array('table_number', 'uniquetable', "on" => "insert"), ); }
and define uniquetable
function in model:
public function uniquetable($attribute,$params) { $record=tabledetail::model()->findbyattributes(array('table_name'=>$this->table_name, "admin_id" => yii::app->user->id)); if(count($record) > 0){ $this->adderror($attribute, 'you have table name'); } }
Comments
Post a Comment