php – url_for在后端的前端 – Symfony

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了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

脚本宝典总结

以上是脚本宝典为你收集整理的php – url_for在后端的前端 – Symfony全部内容,希望文章能够帮你解决php – url_for在后端的前端 – Symfony所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。