views:

4822

answers:

2

Hi guys - check out this website www.fltdata.com. For some reason the home link no matter what page you go on instead of pointing to the home page it points to the current page. It works fine on my localhost but online its behaving like this. The href value of the home link is just : $this->baseUrl()

Whats wrong here..

=== EDIT===

Well I have created a helper which is as below:

class Zend_View_Helper_BaseUrl
{
    protected $_baseUrl;

    function __construct()
    {
        $fc = Zend_Controller_Front::getInstance();
        $this->_baseUrl =  $fc->getBaseUrl();
    }

    function baseUrl()
    {
     return $this->_baseUrl;
    }
}

ANd this is I guess whats being called whenever I call $this->baseUrl. Could this be the problem - however it works okay in my localhost and not online so - must be some kind of configuration issue - where should I look?

+4  A: 

It's hard to tell what's going wrong here without knowing more details about your ZF setup and e.h. the url-rewriting-setup. The logic behind Zend_Controller_Request_Http::getBaseUrl() - this is where your call to Zend_View_Helper_BaseUrl::baseUrl() will beproxied to if no baseUrl is set explicitly in the front-controller - is quite complex and involves 4 different server variables (and some more in the process of determining the current request URI).

The easiest thing to overcome this problem would perhaps be to set the baseUrl (relative to the server root) on the front-controller in your bootstrap. If you're using the new Zend_Application-bootstrapping you'll just have to add

resources.frontController.baseUrl = "/subdir"

to your configuration.

EDIT

Your helper more or less resembles the original baseUrl-helper shipped with the ZF. The original one also proxies to Zend_Controller_Front::getBaseUrl(). Which version of ZF do you use? Is there a reason why you don't use the shipped baseUrl-helper?

Have you tried to set the baseUrl in your bootstrapping explicitly?

Stefan Gehrig
Theres a lot on Zend I'm quite unaware of :( - I posted my helper function - is something wrong there?
Ali
Actually I was just following a tutorial and the site kinda build up from that - I don't think I'm setting the baseUrl in my bootstrap file at all anywhere
Ali
Have you tried to set the baseUrl explicitly? What's the result?Have you tried using the shipped baseUrl-helper? What's the result?
Stefan Gehrig
+1  A: 

I usually use a configuration object for base url and then define it in the index.php in public/index.php

    $config = new Zend_Config_Ini(
        APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV);
    $baseUrl = $config->baseHttp;
    define('BASE_URL', $baseUrl);`

in the configs/application.ini I have this under production section

[production]
baseHttp                            = "http://whatever.net"

This way if I ever need to use a different base url in developement I could just add a diiferent variable for baseHttp personally I think if you want a the baseurl not to get convoluted it is a simpler approach than wrapping in its own class. Sometimes OOP is too much OOP. Plus it would make an installation program more easier to manage. You could even get the $_SERVER variable to get the hostname and wrap it with http://