0
votes

My Apps require cross application linking and after meticulously following the blog at http://symfony.com/blog/cross-application-links

I got one of them working and one of them not working. The link to the backend application from the frontend works fine but not the link to the frontend on the backend code? Basically I have on my backendConfiguration.class.php file :

protected $frontendRouting = null ;

  public function generateFrontendUrl($name, $parameters = array())
  {
    return 'http://localhost:8080/frontend_dev.php'.$this->getFrontendRouting()->generate($name, $parameters);
  }

  public function getFrontendRouting()
  {
    if (!$this->frontendRouting)
    {
      $this->frontendRouting = new sfPatternRouting(new sfEventDispatcher());

      $config = new sfRoutingConfigHandler();
      $routes = $config->evaluate(array(sfConfig::get('sf_apps_dir').'/frontend/config/routing.yml'));

      $this->frontendRouting->setRoutes($routes);
    }

    return $this->frontendRouting;
  }

In my template I got:

echo link_to('Log out', sfContext::getInstance()->getConfiguration()->generateFrontendUrl('dashboard/login') )

dashboard/login is a valid path but this returns: The route does not exist ...500 internal server error

What do you guys reckon ?

Also posting my routing.yml file for reference:

# default rules
homepage:
  url:   /
  param: { module: dashboard, action: index }

# generic rules
# please, remove them by adding more specific rules
default_index:
  url:   /:module
  param: { action: index }

default:
  url:   /:module/:action/*
1

1 Answers

1
votes

Did you try to put a real route with the dasboard/login url in your frontend routing.yml ?

dashboard_login:
  url:   /dashboard/login
  param: { module: dashboard, action: login }

# default rules
homepage:
  url:   /
  param: { module: dashboard, action: index }

# generic rules
# please, remove them by adding more specific rules
default_index:
  url:   /:module
  param: { action: index }

default:
  url:   /:module/:action/*

And then call the route name instead of the module/action:

echo link_to('Log out', $sf_context->getConfiguration()->generateFrontendUrl('dashboard_login') )

Ps: you can use $sf_context in a template instead of sfContext::getInstance().