Zendframework baseUrl view helper in bootstrap

My site uses the zend framework and works in a subfolder, for example: http://www.example.com/sub/folder . Now I want to add my css links from / sub / folder / to make css load on pages like http://www.example.com/sub/folder/product/abc , I thought I found a view helper for this BaseUrl, but BaseUrl seems to work only in real view files, not in the bootstrap class. Does anyone know the reason for this and the exclusive workaround?

This is a snippet of my boodstrap class.

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    protected function _initStylesheet()
    {
        $this->_logger->info('Bootstrap ' . __METHOD__);

        $this->bootstrap('view');
        $this->_view = $this->getResource('view');

        $this->_view->headLink()->appendStylesheet($this->_view->baseUrl('/css/main.css'));
    }
}
+3
source share
3 answers

, baseUrl() Bootstrap. , Zend_Controller_Front Zend_Controller_Request.

, , .

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    protected function _initRequest()
    {
        $this->_logger->info('Bootstrap ' . __METHOD__);

        $this->bootstrap('FrontController');

        $front = $this->getResource('FrontController');
        $request = new Zend_Controller_Request_Http();

        $front->setRequest($request);
    }

    protected function _initStylesheet()
    {
        $this->_logger->info('Bootstrap ' . __METHOD__);

        $this->bootstrap('view');
        $this->_view = $this->getResource('view');

        $this->_view->headLink()->appendStylesheet($this->_view->baseUrl('/css/main.css'));
    }
}
+5

baseUrl,

Zend_Controller_Front::getInstance()->getBaseUrl();

-ZF-:

substr($_SERVER['PHP_SELF'], 0, -9);
+1

Actually, you do not need to get baseUrl, because ZF is already doing this for you. You just need to pay attention to your path. Do not use the first slash! otherwise ZF will return the remote address.

Just use '$this->_view->headLink()->appendStylesheet('css/main.css');'

0
source

Source: https://habr.com/ru/post/1727435/


All Articles