写一个class
// apps/backend/config/backendConfiguration.class.php
class backendConfiguration extends sfApplicationConfiguration
{
protected $frontendRouting = null;
public function generateFrontendUrl($name, $parameters = array())
{
return 'http://frontend.example.com'.$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;
}
}
在action中可以用下面的动作,就可以跳到其它的app中的动作,下面的‘hello’,是frontend/config配置文件routing中的一条路由规则
$this->redirect($this->getContext()->getConfiguration()->
generateFrontendUrl('hello', array('name' => 'Bar')));
function link_to_frontend($name, $parameters)
{
return sfProjectConfiguration::getActive()->
generateFrontendUrl($name, $parameters);
}

有多个前端app时,比如mobile_frontend和pc_frontend。
不用hard code指定frontend或者backend,用参数指定app名
(甚至env)或许更好些。
Comment 由 chen — 2009-05-25 @ 17:34
。。写一半掉线。
主机名的地方也用的hard code,用
sfContext::getInstance()->getRequest()->getHost()或许更好。
Comment 由 chen — 2009-05-25 @ 17:44
take a look at this blog:-)
http://www.symfony-project.org/blog/2009/02/17/cross-application-links
Comment 由 Jayson — 2009-05-27 @ 13:58