我用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)
原文地址:https://www.jb51.cc/php/136376.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。