Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

GetPreviousControllerName getting the base controller instead of child controller

Hello I am trying to use the GetPreviousControllerName on the Phalcon dispatcher in order to retrieve the last controller name. This however returns my baseController and not the child that extends the base. Here is a small example:

From

class TestController extends BaseController
{
    //Calls an action on the base class
    //On error 
    $this->dispatcher->setParam("message", "Failure!!");
    $this->dispatcher->setParam("Id", 1234);
                    $this->dispatcher->forward(array("controller" => "general", "action" => "errorConfirmation"));
}

Going To

class GeneralController extends BaseController
{
        public function errorConfirmationAction()
        {
                    // show error then return to
                    $this->view->setVar("link", $this->dispatcher->getPreviousControllerName() . "/view/" . $Id);
        }
}

This returns Base/view/1234

I need it to return Test/View/1234 is this possible?



44.9k

This seems like a bug that could possibly be easily fixed by someone familiar with that code. I recommend reporting it at https://github.com/phalcon/cphalcon/issues



44.9k

Also which version of Phalcon are you using?



1.5k
edited Dec '15

I am using Phalcon 2

Also which version of Phalcon are you using?



44.9k

I'm using 2.0.8. It just seems like it is a bug but I couldn't determine it from looking at the Dispatcher Zephyr code and I can't go more into it now.

Try a temporary work around with using getLastController() and then parsing the class name from that to determine the name of the controller, converting it to lower case, etc.

I'd report this bug as it seems like an obvious issue.



44.9k

I've had to do a several workarounds with Phalcon and I've been able to have other people fix the bug and in one difficult case I had to get in there and do it myself. It works out in the end.



44.9k
Accepted
answer

Definitely update to the very latest before trying something else.



1.5k

I am passing the controller through the dispatcher as I havent found an easy work around