Zend Framework HTTPS URL

时间:2011-06-21 14:06:32

标签: zend-framework url routing https

是否有更多或更少的标准方法来指定使用明确指定的方案创建URL的路由?

我已尝试过指定here的解决方案,但由于以下几个原因,这对我来说并不是很好:

  1. 它不支持基本网址请求属性。实际上,当明确指定URL方案时,重写路由器会忽略它。
  2. 需要为每个与方案相关的URL指定单独的静态路由(由于忽略基本URL,因此无法使用主机名路由链接模块路由)。
  3. 只要请求对象在FrontController中不存在,就需要在bootstrap中的路由器初始化时手动确定HTTP_HOST。

2 个答案:

答案 0 :(得分:9)

使用ServerUrl和Url视图助手的组合来构建您的URL,例如(查看上下文)

<?php $this->getHelper('ServerUrl')->setScheme('https') ?>
...
<a href="<?php echo $this->serverUrl($this->url(array(
    'url' => 'params'), 'route', $reset, $encode)) ?>">My Link</a>

答案 1 :(得分:2)

您可以编写自己的自定义View帮助程序来撰写URL。看看http://www.evilprofessor.co.uk/239-creating-url-in-zend-custom-view-helper/

<?php 

class Pro_View_Helper_LinksUrl  
    extends Zend_View_Helper_Abstract  
{  
    /** 
     * Returns link category URL 
     * 
     * @param  string          $https 
     * @param  string          $module 
     * @param  string          $controller 
     * @param  string          $action 
     * @return string Url-FQDN 
     */  
    public function linksUrl($https = false, $module = 'www',  
        $controller = 'links', $action = 'index')  
    {  
        $router = Zend_Controller_Front::getInstance()->getRouter();  

        $urlParts = $router->assemble(array(  
            'module'     => $module,  
            'controller' => $controller,  
            'action'     => $action,  
        ), 'www-index');  

        $FQDN = (($https) ? "https://" : "http://") . $_SERVER["HTTP_HOST"] . $urlParts;

        return $FQDN;
    }  
}