Domanda

With below code i have set layout and view files path.

 class DemoMet_IndexController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {

        $theme = 'metronic_v3';
        $layout_name = 'default';

        $layout = Zend_Layout::getMvcInstance();

        $layoutPath = APPLICATION_PATH . DIRECTORY_SEPARATOR. 'themes'. DIRECTORY_SEPARATOR . $theme . DIRECTORY_SEPARATOR. 'layouts'. DIRECTORY_SEPARATOR. 'scripts'. DIRECTORY_SEPARATOR;
        $layout->setLayoutPath($layoutPath);
        $layout->setLayout($layout_name);

        $viewPath = APPLICATION_PATH . DIRECTORY_SEPARATOR. 'themes'. DIRECTORY_SEPARATOR . $theme . DIRECTORY_SEPARATOR. 'views'. DIRECTORY_SEPARATOR;
        $layout->getView()->setBasePath($viewPath);

    }


}

but when I access the url "http://project.localhost/demoMet/index/" . Error message

with message 'script 'index/index.phtml' not found in path project/application/modules/demoMet/views/scripts/

Though the view files path is set but it searching in default script folder

È stato utile?

Soluzione

Add a _init function to your main application Bootatrp.php file!

Bootstrap.php

protected function _initViewHelpers() {
    //Bootstrap view 
    $this->bootstrap('view');
    //get bootstrapped view
    $view = $this->getResource('view');
    $view->addScriptPath(APPLICATION_PATH."/templates/default/views/scripts");
    //$view->addScriptPath($theme);
    $view->addHelperPath(APPLICATION_PATH."/templates/default/views/helpers/", "Administration_View_Helper");

}  

Altri suggerimenti

Maybe you can try this:

public function indexAction()
{

    $theme = 'metronic_v3';
    $layout_name = 'default';

    // without the last DIRECTORY_SEPARATOR
    $layoutPath = APPLICATION_PATH . DIRECTORY_SEPARATOR. 'themes'. DIRECTORY_SEPARATOR . $theme . DIRECTORY_SEPARATOR. 'layouts'. DIRECTORY_SEPARATOR. 'scripts';

    $this->_helper->layout->setLayout($layout_name);
    $this->_helper->layout->setLayoutPath($layoutPath);

    // with add 'scripts' after the last DIRECTORY_SEPARATOR
    $viewPath = APPLICATION_PATH . DIRECTORY_SEPARATOR. 'themes'. DIRECTORY_SEPARATOR . $theme . DIRECTORY_SEPARATOR. 'views'. DIRECTORY_SEPARATOR . 'scripts';

    $this->view->setBasePath($viewPath);
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top