Zend Framework HTTPS URL

旧街凉风 提交于 2019-12-22 04:17:11

问题


Is there any more or less standard way to specify a route that would create URL's with explicitly specified scheme?

I've tried the solution specified here but it's not excellent for me for several reasons:

  1. It doesn't support base url request property. Actually rewrite router ignores it when URL scheme is specified explicitly.
  2. It's needed to specify separate static route for each scheme-dependent URL (it's not possible to chain module route with hostname route because of base url is ignored).
  3. It's needed to determine HTTP_HOST manually upon router initialization in bootstrap as long as request object is not present within FrontController yet.

回答1:


Use a combination of the ServerUrl and Url view helpers to construct your URLs, eg (view context)

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



回答2:


You can write your own custom View helper for composing an URL. Take a look at the 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;
    }  
}


来源:https://stackoverflow.com/questions/6426628/zend-framework-https-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!