• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List

E:/E/GEAMP/www/openbiz/openbiz/others/Zend/View/Helper/BaseUrl.php

00001 <?php
00024 require_once 'Zend/View/Helper/Abstract.php';
00025 
00034 class Zend_View_Helper_BaseUrl extends Zend_View_Helper_Abstract
00035 {
00041     protected $_baseUrl;
00042 
00051     public function baseUrl($file = null)
00052     {
00053         // Get baseUrl
00054         $baseUrl = $this->getBaseUrl();
00055 
00056         // Remove trailing slashes
00057         if (null !== $file) {
00058             $file = '/' . ltrim($file, '/\\');
00059         }
00060 
00061         return $baseUrl . $file;
00062     }
00063 
00070     public function setBaseUrl($base)
00071     {
00072         $this->_baseUrl = rtrim($base, '/\\');
00073         return $this;
00074     }
00075 
00081     public function getBaseUrl()
00082     {
00083         if ($this->_baseUrl === null) {
00085             require_once 'Zend/Controller/Front.php';
00086             $baseUrl = Zend_Controller_Front::getInstance()->getBaseUrl();
00087 
00088             // Remove scriptname, eg. index.php from baseUrl
00089             $baseUrl = $this->_removeScriptName($baseUrl);
00090 
00091             $this->setBaseUrl($baseUrl);
00092         }
00093 
00094         return $this->_baseUrl;
00095     }
00096 
00103     protected function _removeScriptName($url)
00104     {
00105         if (!isset($_SERVER['SCRIPT_NAME'])) {
00106             // We can't do much now can we? (Well, we could parse out by ".")
00107             return $url;
00108         }
00109 
00110         if (($pos = strripos($url, basename($_SERVER['SCRIPT_NAME']))) !== false) {
00111             $url = substr($url, 0, $pos);
00112         }
00113 
00114         return $url;
00115     }
00116 }

Generated on Thu Apr 19 2012 17:01:18 for openbiz by  doxygen 1.7.2