Hi,
i have a model method upload file, and when the method crashes it throws an exception. What happens is that i end up getting this:
What can i do to just display a user friendly error message the "right way" istead of this coding exception thing?
my model:
public function uploadFile(){
$uploadedFile = CUploadedFile::getInstance($this,'path_to_file');
if(!empty($uploadedFile)){
try{
$uploadedFile->saveAs(Constantes::path_to_file.$uploadedFile->name,FALSE);
$this->path_to_file = Constantes::path_to_file.$uploadedFile->name;
//save Thumb
$image = new EasyImage(Constantes::path_to_file.$uploadedFile->name);
$image->resize(100, 100);
$image->save(Constantes::path_to_file.'thumbs/'.'thumb_'.$uploadedFile->name);
}catch(Exception $e){
throw new Exception("Erro ao fazer upload da imagem");
}
}
}
the controller snippet of the called method:
if(isset($_POST['ComentarioDeComentario'])){
$model = new ComentarioDeComentario();
$model->uploadFile();
$model->conteudo = strip_tags($_POST['ComentarioDeComentario']['conteudo']);
$model->comentario_id = $_POST['ComentarioDeComentario']['comentario_id'];
$model->user_id = Yii::app()->user->getState('id');
if($model->save()){
$this->refresh();
}
}
thks!