php – url_for在后端的前端 – Symfony

我用symfony routing.yml在frontend上做了很好的网址.在前端我可以使用例如:
url_for('@news',$news);

这为我生成

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

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

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

有可能在后端为前端生成这些链接吗?

在apps / frontend / config / 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

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...