Thursday, July 30, 2009

Re: setFlash and redirect problem

Error before redirect causes "blank page". Turn debug on and look at
this error.

On Jul 29, 10:29 pm, Eddy Josafat <eddyjosa...@gmail.com> wrote:
> I have same problem and I don't use any translation.
>
> $this->Session->setFlash('Contraseña modificada', 'notificación');
> $this->redirect(array('controller' => 'gestion', 'action' =>
> 'display', 'inicio'));
>
> I get a blank page and no redirect with previous code. If I comment
> the line that sets the flash message it works fine.
>
> In another place of my app, if I create a new record, flash + redirect
> works perfectly:
>
> function nueva() {
>                 if (!empty($this->data)) {
>                         // Guardar fichero y almacenar url si se ha subido una imagen
>                         $url = $this->_url_uploaded_file($this->data['Document']
> ['submittedfile']);
>                         if ($url) {
>                                         $this->data['Noticia']['url_imagen'] = $url;
>                         } // $url
>                         if ($this->Noticia->save($this->data)) {
>                                 $this->Session->setFlash('Noticia guardada con éxito',
> 'notificacion');
>                                 $this->redirect(array('action' => 'listado'));
>                         } else {
>                                 $this->Session->setFlash('No ha podido almacenarse la noticia',
> 'error');
>                         } //   $this->Documento->save($this->data)
>                 } // !empty($this->data)
>         }
>
> but when I'm doing editing an existing record:
>
> function editar($id = null) {
>                 $this->Noticia->id = $id;
>                 if (empty($this->data)) {
>                         $this->data = $this->Noticia->read();
>                 } else {
>                         $url = $this->_url_uploaded_file($this->data['Document']
> ['submittedfile']);
>                         if ($url) {
>                                 // Borrar el anterior
>                                         $noticia = $this->Noticia->read();
>                                         if ( $noticia['Noticia']['url_imagen'] != $url ) {
>                                                 @unlink($noticia['Noticia']['url_imagen']);
>                                         }
>                                         $this->data['Noticia']['url_imagen'] = $url;
>                         }
>                         if ($this->Noticia->save($this->data)) {
>                                 $this->Session->setFlash('Noticia modificada', 'notificación');
>                                 $this->redirect(array('action' => 'listado'));
>                         } else {
>                                 $this->Session->setFlash('No ha podido almacenarse la noticia',
> 'error');
>                         }
>                 }
>         }
>
> flash + redirect causes a blank page.
>
> What's the matter aobut flash messages and redirects?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: