Are there some proper Zend methods for:
a) receiving path to /public directory
b) receiving application url
Actually I'm using methods defined in Controller, but it feel right to use ready methods if they exits.
protected function _getApplicationUrl() {
return $_SERVER['SERVER_NAME'];
}
protected function _getPublicPath() {
return realpath(APPLICATION_PATH . '/../public/');
}
Regarding the application URL, Zend_Controller_Request_Http
has a getRequestUri()
method, but it deliberately (and somewhat frustratingly) excludes the scheme and hostname parts of the URL. In my apps I have resorted to grabbing $_SERVER['HTTP_HOST']
in the bootstrap and storing it in the registry so that I can use it later when constructing full URLs.
And from memory, no, there isn't any built-in method to get the location of the public
folder, but the code you have is fine. Most apps I've seen define()
all the paths in index.php
, which I suppose is slightly safer (only because the path names get set sooner and become absolutely immutable) and ever so slightly faster, but lets not get into a debate about micro-optimizations! :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With