Zend Framework: get public path, get app url

Are there any suitable Zend methods for:

a) getting the path to the / public directory

b) getting the application url

In fact, I use the methods defined in the controller, but they have the right to use ready-made methods if they exit.

protected function _getApplicationUrl() {
    return $_SERVER['SERVER_NAME'];
}

protected function _getPublicPath() {
    return realpath(APPLICATION_PATH . '/../public/');
}
+5
source share
4 answers

Regarding the application URL, it Zend_Controller_Request_Httphas a method getRequestUri(), but it intentionally (and somewhat disappointing) excludes part of the URL of the scheme and node. In my applications, I resorted to grabbing $_SERVER['HTTP_HOST']into bootstrap and storing it in the registry so that I could use it later to create full URLs.

, public, . , define(), index.php, , , ( , ) , -!: -)

+6

1) ZF/public, $this->baseUrl(); $this->view->baseUrl(); . 2) $this->getRequest()->getHttpHost();

+3

a) /

php- getcwd() - (, output)/home/my_cp/public_html/my_site.loc/WWW "). , .

+1
source
protected function _getPublicPath() {
    chdir(APPLICATION_PATH);
    return realpath("../public");
}
0
source

All Articles