Zend Framework: how do you set your layout directory in a modular application?

The directory structure that I am trying to achieve will be as follows:

application/default/views/layouts/layout.phtml
application/default/views/scripts/index/index.phtml
application/admin/views/layouts/layout.phtml
application/admin/views/scripts/index/index.phtml
library/Zend
config/config.ini
public/index.php (bootstrap)

but I can't figure out how to let Zend find my layout.phtml in each of my modules.

in my bootstrap i have:

define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application/'));
define('APPLICATION_ENVIRONMENT', 'testing');

//setup path to our library files
set_include_path( APPLICATION_PATH . '/../library' . PATH_SEPARATOR .
                  get_include_path() );

//register the autoloader
require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload(); 

//set config in the registry
$config = new Zend_Config_Ini( APPLICATION_PATH . '/../config/config.ini', APPLICATION_ENVIRONMENT ); 
Zend_Registry::set('config', $config);

//setup logging
$writer = new Zend_Log_Writer_Stream(APPLICATION_PATH . '/../log/debug.log');
$logger = new Zend_Log($writer);
Zend_Registry::set('logger', $logger);

//run!
$frontController = Zend_Controller_Front::getInstance();
$frontController->addModuleDirectory(APPLICATION_PATH);
//initialize Zend_Layout MVC helpers
Zend_Layout::startMvc();

$frontController->throwExceptions(true);

try {

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

} catch (Exception $exception) {

    echo '<html><body><center>'  . 'An exception occured while dispatching the front controller.'; 
    if (defined('APPLICATION_ENVIRONMENT') && APPLICATION_ENVIRONMENT != 'production'  ) {
        echo '<br /><br />' . $exception->getMessage() . '<br />'  . '<div align="left">Stack Trace:' . '<pre>' . $exception->getTraceAsString() . '</pre></div>'; 
    }
    echo '</center></body></html>';
    exit(1);
}

Where am I going wrong?

Update:

I have not considered this for a long time, so the decision made may be incompatible. If someone wants to post a more relevant solution to this issue (i.e. ZF 1.8+), do it! This would be helpful for others looking for a solution to this.

+3
source share
2 answers

Zend_Layout, , . , , .

+4

Zend Framework 1.12 ( ): !

application.ini , orther :

resources.layout.layout = "layout"

... , . "layoutPath" , Zend_Layout "/modules//views/scripts" "layout.phtml"

zend, :

resources.layout.layoutPath = APPLICATION_PATH "layouts/scripts"

, "layout.phtml" . , , , "layout.phtml" "Application/modules//views/scripts".

, .

!

, , :

resources.layout.pluginClass = "YourLibrary_Controller_Plugin_Layout"

.

+2

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


All Articles