在Zend中使用gethostname的位置

Objective: I want to know if it is possible to determine whether the host is localhost or my development site's host in one place in the Zend Framework and use that determination across the rest of the site via a session variable.

Details: I'm working on a website with a small group of people. We're using svn tools to merge our code, and testing on localhost before moving changes and additions up to a development server. Since the same code is used in every platform we use gethostname() in php to determine if we're accessing our site through localhost or the server. We need this so we can set file paths appropriately (http://localhost/images/dog.jpg vs https://mysite.com/images/dog.jpg). Initially, every time this came into play we set a variable $host in the controller's public function init() that contained the appropriate string to use throughout that page. Then we switched to putting $host in a session variable which significantly decreased the amount of redundant code. But I'm sure there is a way to set this in one place and be done with it, but I don't know where this place would be (within the Zend framework). The index landing page doesno't work because users will likely enter from other places. My best guess was setting it in the layout, but that gives me errors because the layout code runs too late the page loading process. Is there a better place to determine the host? Is there a way to prioritize it within the layout code so it somehow executes before it's needed in the page?

Code:

if(!isset($_SESSION['hostname'])){
  $hostname = gethostname();
  if ($hostname == 'prodserver') { 
    $_SESSION['hostname'] = 'https://mysite.com'; 
  } else { 
    $_SESSION['hostname'] = 'http://localhost'; 
  }
}

Our current method works just fine, but I can't shake the feeling that there must be a better way! If you know it - I'd love to hear it. Thanks!

To answer the question in your comment, no, session variables are by definition user-specific. However ZF (by convention) sets the constant APPLICATION_ENV which can be used to do environment-specific checks. You can also set variables (including the baseUrl) via. application.ini which would be how would you solve the problem in your question if you needed to.