Advertisement
christiansalazarh

ejemplo de eliminacion con manejo de mensajes

Feb 28th, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.04 KB | None | 0 0
  1. private function tryDelete($className,$id,$frase='No se pudo eliminar.') {
  2.                 $base = new $className;
  3.                 $model= $base->findByPk($id);
  4.                 if($model == null) throw new Exception("id invalido");
  5.                 try{
  6.                         $model->delete();
  7.                 }
  8.                 catch(Exception $e){
  9.                        
  10.                         $extra = strstr($e->getMessage(),"fk_");
  11.                         if($index = strpos($extra,"FOREIGN"))
  12.                                 $extra = substr($extra,0,$index);
  13.                
  14.                         $extra = rtrim($extra,"`ยด'\'\" ");
  15.                         if(isset(Yii::app()->params['errores_fk'][$extra]))
  16.                                 $extra = Yii::app()->params['errores_fk'][$extra];
  17.                        
  18.                         Yii::log("tryDelete {$className} id={$id}\n".$extra."\n".$e->getMessage(),"info");
  19.                                
  20.                         throw new Exception($frase."\n\n".$extra);
  21.                 }
  22.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement