Best practice to create absolute URLs with Zend framework?

前端 未结 5 1889
南笙
南笙 2021-02-01 23:26

Is there a best practice for creating absolute URLs using the Zend framework? I wonder if there is some helper or if this would just be concatenating the scheme, host, etc. from

5条回答
  •  情书的邮戳
    2021-02-01 23:50

    phpfour's way is OK, but you have to check for https://, ftp:// and mailto: too... :)

    I prefefer having all urls root-absolute (/files/js/jquery.js). The "hardcore zend way" is

    baseUrl('css/base.css'); 
    //will return /myapp/public/css/base.css
    
    echo $this->serverUrl() . $this->baseUrl('css/base.css');
    //will return http://www.example.com/myapp/public/css/base.css
    
    echo '//' . $this->getHelper('ServerUrl')->getHost() . $this->baseUrl('css/base.css');
    //will return protocol relative URL //www.example.com/myapp/public/css/base.css
    

提交回复
热议问题