0

我的应用程序需要跨应用程序链接,并且在仔细关注 http://symfony.com/blog/cross-application-links上的博客之后

我让其中一个工作,其中一个不工作。从前端到后端应用程序的链接工作正常,但后端代码上的前端链接不正常?基本上我有我的 backendConfiguration.class.php 文件:

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;
  }

在我的模板中,我得到:

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

仪表板/登录是一个有效的路径,但这会返回: 路由不存在 ...500 内部服务器错误

你们怎么看?

还发布我的 routing.yml 文件以供参考:

# 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/*
4

1 回答 1

1

您是否尝试在前端 routing.yml 中放置带有 dasboard/login url 的真实路由?

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/*

然后调用路由名称而不是模块/动作:

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

Ps:您可以$sf_context在模板中使用而不是sfContext::getInstance().

于 2012-04-13T07:26:28.237 回答