Yii Framework Forum: Call To A Member Function Saveas() On A Non-Object - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Call To A Member Function Saveas() On A Non-Object salvar imagem na pasta especificada Rate Topic: -----

#1 User is offline   nickezaro 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 22-August 12

Posted 25 October 2012 - 01:36 PM

no momento de salvar ele diz que a chamada saveAs() nao é um objeto!

   if (isset($_POST['ImagemComida'])) {
                    $rnd = rand(0, 9999);  // generate random number between 0-9999
                    $imagemcomida->attributes = $_POST['ImagemComida'];
                    
                    $uploadedFile = CUploadedFile::getInstance($imagemcomida, 'imagemcomida');
                    $fileName = "{$rnd}-{$uploadedFile}";  // random number + file name
                    $imagemcomida->imagem = $fileName;
                    $imagemcomida->id_comida = $model->id;

                    if ($imagemcomida->save()) {
                        if (is_dir(Yii::app()->basePath . '/../images/comida/' . Yii::app()->user->id)) {
                            $uploadedFile->saveAs(Yii::app()->basePath . '/../images/comida/' . Yii::app()->user->id . '/' . $fileName);  // image will uplode to rootDirectory/banner/
                        } else {
                            mkdir(Yii::app()->basePath . '/../images/comida/' . Yii::app()->user->id, 0700);
                            $uploadedFile->saveAs(Yii::app()->basePath . '/../images/comida/' . Yii::app()->user->id . '/' . $fileName);  // image will uplode to rootDirectory/banner/
                        }
                    } else {
                        $this->redirect(array('index'));
                    }
                } 

0

#2 User is offline   Lothor 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 147
  • Joined: 05-August 11
  • Location:Brazil

Posted 26 October 2012 - 08:57 AM

nickezaro, dá uma olhada nessa extensão: CFile.

É muito mais fácil manipular arquivos com ela, resolvi meu problema facilmente.
0

#3 User is offline   nickezaro 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 22-August 12

Posted 26 October 2012 - 12:08 PM

Será que voce poderia me mostrar como posso fazer?

View PostLothor, on 26 October 2012 - 08:57 AM, said:

nickezaro, dá uma olhada nessa extensão: CFile.

É muito mais fácil manipular arquivos com ela, resolvi meu problema facilmente.

0

#4 User is offline   nickezaro 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 22-August 12

Posted 29 October 2012 - 11:02 AM

ja resolvi era somente necessario um true

$uploadedFile->saveAs(Yii::app()->basePath . '/../images/comida/' . Yii::app()->user->id . '/' . $fileName, true)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users