$ this-_forward () and Zend Framework

1

Sirs,

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

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

Another thing is that forward causes url to not change .... it redirects, but url stays with 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.";

    }
    
asked by anonymous 12.02.2015 / 18:00

1 answer

2

The operation of _forward() is the same. It redirects to another controller or action after receiving the request. The URL remains the same because it does not create a new request , just as it does the redirect() method which, yes, throws header() .

I suggest using redirect() yourself or implementing the deletion in AJAX, if you want something faster and more interactive.

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

controller :

Set a message:

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

Retrieve previously set message:

$this->_helper->FlashMessenger->getMessages();
    
12.02.2015 / 18:48