 Написал плагин для ZendFramework’a, который подключает стили и JavaScript’ы. Для плагина надо зарегистрировать в Zend_Registry два параметра:
Написал плагин для ZendFramework’a, который подключает стили и JavaScript’ы. Для плагина надо зарегистрировать в Zend_Registry два параметра:
pathStyle — путь к стилям
pathJS — путь к JavaScript’ам
Плагин проверяет на существование файлы. Например мы обратились к странице fritool.ru/modules/controller/action/. Скрипт будет проверять следующие файлы на существование:
pathStyle/modules.css
pathStyle/modules/controller.css
pathStyle/modules/controller/action.css
pathJS/modules.js
pathJS/modules/controller.js
pathJS/modules/controller/action.js
Код плагина:
class Dev_Plugin_View extends Zend_Controller_Plugin_Abstract
{
    public function preDispatch(Zend_Controller_Request_Abstract $request)
    {
        $view = Zend_Controller_Action_HelperBroker::getExistingHelper('ViewRenderer')->view;
        $pathStyle = Zend_Registry::get('pathStyle');
        $pathJS    = Zend_Registry::get('pathJS');
        //----------------------------- Styles -----------------------------
        $view->headLink()->appendStylesheet($pathStyle . 'site.css?');
        if (file_exists($_SERVER['DOCUMENT_ROOT'] . $pathStyle . $this->_request->module . '.css')) {
            $view->headLink()->appendStylesheet($pathStyle . $this->_request->module . '.css');
        }
        if (file_exists($_SERVER['DOCUMENT_ROOT'] . $pathStyle . $this->_request->module . DIRECTORY_SEPARATOR . $this->_request->controller . '.css')) {
            $view->headLink()->appendStylesheet($pathStyle . $this->_request->module . DIRECTORY_SEPARATOR . $this->_request->controller . '.css');
        }
        if (file_exists($_SERVER['DOCUMENT_ROOT'] . $pathStyle . $this->_request->module . DIRECTORY_SEPARATOR . $this->_request->controller . DIRECTORY_SEPARATOR . $this->_request->action . '.css')) {
            $view->headLink()->appendStylesheet($pathStyle . $this->_request->module . DIRECTORY_SEPARATOR . $this->_request->controller . DIRECTORY_SEPARATOR . $this->_request->action . '.css');
        }
        //----------------------------- Scripts -----------------------------
        if (file_exists($_SERVER['DOCUMENT_ROOT'] . $pathJS . $this->_request->module . '.js')) {
            $view->headScript()->appendFile($pathJS . $this->_request->module . '.js');
        }
        if (file_exists($_SERVER['DOCUMENT_ROOT'] . $pathJS . $this->_request->module . DIRECTORY_SEPARATOR . $this->_request->controller . '.js')) {
            $view->headScript()->appendFile($pathJS . $this->_request->module . DIRECTORY_SEPARATOR . $this->_request->controller . '.js');
        }
        if (file_exists($_SERVER['DOCUMENT_ROOT'] . $pathJS . $this->_request->module . DIRECTORY_SEPARATOR . $this->_request->controller . DIRECTORY_SEPARATOR . $this->_request->action . '.js')) {
            $view->headScript()->appendFile($pathJS . $this->_request->module . DIRECTORY_SEPARATOR . $this->_request->controller . DIRECTORY_SEPARATOR . $this->_request->action . '.js');
        }
    }
}
Для того, чтобы плагин заработал его надо зарегистрировать в приложении.
Код:
$frontController->registerPlugin(new Dev_Plugin_Main());