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?
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?
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://
Zend Framework is always returning the current page because you are not using a trailing slash after calling $this->baseUrl();.
To resolve the issue append a trailing slash after calling $this->baseUrl(); in your view like so:
The Correct Way
<a href="<?php echo $this->baseUrl() . "/"; ?>">Home Link</a>
or
<a href="<?php echo $this->baseUrl(); ?>/">Home Link</a>
Omitting the trailing slash results in a link to the page you're currently viewing.
The Incorrect Way
<a href="<?php echo $this->baseUrl(); ?>">Home Link</a>
I just had a similar problem when using $this->baseUrl in my view. I found using this would give me the url of the current page:
baseUrl; ?>">
http://www.yourwebaddress.com/current-page
and this would give me the real baseurl regardless of the current page (note the slash added to the end of the url)
baseUrl; ?>/">
http://www.yourwebaddress.com/