Symfony 1.4 Cross APplication link fail

回眸只為那壹抹淺笑 提交于 2019-12-25 01:12:27

问题


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:


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().



来源:https://stackoverflow.com/questions/10136416/symfony-1-4-cross-application-link-fail

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!