Takayuki Sato
Takayuki Sato

Reputation: 1043

How can I guess action name and module name from URL in symfony?

For example, I have a referer URL. I want to redirect to a page according to the previous page's module.

Upvotes: 1

Views: 1212

Answers (1)

Visavì
Visavì

Reputation: 2333

There is a code snippet on this page. To get module and action of the previous page, you will use the referer:

    $referer = sfContext::getInstance()->getRequest()->getReferer();
    // you have to check if the referer is not empty and is a page of your site
    ....
    // then get the module and action:
    $url = parse_url($referer);
    $path = trim($url['path'], '/');
    if (!sfConfig::get('sf_no_script_name') && $pos = strpos($path, '/') )
    {
        $path = substr($path, $pos+1);
    }
    $params = sfContext::getInstance()->getRouting()->findRoute('/'.$path);
    $module = $params['parameters']['module'];
    $action = $params['parameters']['action'];

Upvotes: 2

Related Questions