2011-12-19 112 views
8

我在前端用symfony routing.yml制作了漂亮的url。在前端,我可以使用,例如:url_for在后端用于前端 - Symfony

url_for('@news', $news); 

这产生了我:

http://mysite.com/frontend_dev.php/news/nice-title/1 

,但如果我在后台使用这个我有:

http://mysite.com/backend_dev.php/news/nice-title/1 

可能产生这些链接后端用于前端?

回答

10

在应用/前端/配置/ frontendConfiguration.class.php使用这样的:

class frontendConfiguration extends sfApplicationConfiguration 
{ 
    protected $backendRouting = null; 

    public function generateBackendUrl($name, $parameters = array(), $absolute = false) 
    { 
    return sfConfig::get('app_site_url').$this->getBackendRouting()->generate($name, $parameters, $absolute); 
    } 

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

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

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

    return $this->backendRouting; 
    } 
} 

这样使用它:

$sf_context->getConfiguration()->generateBackendUrl('my_custom_route', array('id' => 1), true) 

点击此处了解详情:http://symfony.com/blog/cross-application-links