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.phalconphp.com/en/latest/api/Phalcon%5Mvc%5Dispatcher.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.



4.5k
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');
    }
}

//...