$this->_forward() and Zend Framework

Asked

Viewed 448 times

1

Sirs,

In the use of $this->_forward() in the Zend Framework 1 we give a redirect to the controller and action we want. In my case this is not working well in the following situation.

I made an appointment, I want that after deletar a record it disappear and already redirect to the same screen where was the query.

Another thing is that the forward causes the url don’t change.... it redirects, but the url is with record parameter ... /apagar?idRegistro=56.

Action:

public function apagarAction()
    {

        $this->_helper->viewRenderer->setNoRender(true);

        $idTel = $this->_getParam('idRegistro');

        $modTel = new Sca_Model_Telefone('sca');
        $idRegistro = $modTel->getAdapter()->quoteInto('idTelefone = ?', $idTel);

        $modTel->delete($idRegistro);

        $this->_forward('consultar', 'index', 'sistel');
        $this->view->deletado = "Registro deletado com sucesso.";

    }

1 answer

2

The functioning of _forward() that’s right. It redirects to another controller or action after receiving the request. The URL remains the same because it does not create a request new, just like the method does redirect() that, this yes, launches a header().

I suggest using the redirect() same or implement the exclusion in AJAX if you want something faster and interactive.

If you use redirect() and want to display messages to the user, can use "Flashmessenger", which has exactly the function of sending messages to request future.

In the controller:

Set a message:

$this->_helper->flashMessenger->addMessage('Mensagem');

Recover previously set message:

$this->_helper->FlashMessenger->getMessages();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.