We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

dispacher.getPreviousControllerName () is null always

I do not know why always getPreviousControllerName () is null.

However getControllerName () tells me the current driver, not the previous one.

https://docs.phalcon.io/en/latest/api/Phalcon_Mvc_Dispatcher.html

It is shared by several objects (incidence -> home incidence -> work) and I need to know what the previous driver to know where to show and redirect.



11.1k
edited May '16

If you want to get the Controller's name from services.php, for example, you can use Routes like this:

$di = new Phalcon\Di\FactoryDefault();

$di->set("getControllerAndActionNames", function () use ($di) {
    $router = $di->getShared('router');
    $ControllerName = $router->getControllerName();
    $ActionName = router->getActionName();

    return $ControllerName.'/'.$ActionName; // This returns "registration/index" for RegistrationController and indexAction
});

And the next you can use redirect (If I understood you correctly, else it's just an example):

// ...

class RegistrationController extends Controller
{
    public function indexAction()
    {
        $this->response->redirect($this->getControllerAndActionNames);
        // If I'm right, it will work like this: $this->response->redirect('registration/index');
    }
}

//...