Symfony 1.4 跨应用程序链接失败 [英] Symfony 1.4 Cross APplication link fail
问题描述
我的应用程序需要跨应用程序链接,并在仔细关注博客后http://symfony.com/blog/cross-application-links
My Apps require cross application linking and after meticulously following the blog at http://symfony.com/blog/cross-application-links
我让其中一个工作,其中一个不工作.从前端到后端应用程序的链接工作正常,但在后端代码上没有到前端的链接?基本上我在我的 backendConfiguration.class.php 文件上有:
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;
}
在我的模板中我得到:
echo link_to('Log out', sfContext::getInstance()->getConfiguration()->generateFrontendUrl('dashboard/login') )
dashboard/login 是一个有效的路径,但这会返回:路由不存在...500 内部服务器错误
dashboard/login is a valid path but this returns: The route does not exist ...500 internal server error
你们怎么看?
同时发布我的routing.yml文件以供参考:
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/*
推荐答案
您是否尝试在前端 routing.yml 中使用 dasboard/login url 放置真实路由?
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:您可以在模板中使用 $sf_context
而不是 sfContext::getInstance()
.
Ps: you can use $sf_context
in a template instead of sfContext::getInstance()
.
这篇关于Symfony 1.4 跨应用程序链接失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!