视图文件不在zend框架中呈现

时间:2014-05-15 11:38:26

标签: php templates zend-framework

使用以下代码我已设置布局和查看文件路径。

 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);

    }


}

但是当我访问网址" http://project.localhost/demoMet/index/" 。 错误消息

  

带有邮件'脚本' index / index.phtml'在路径中找不到   项目/应用/模块/ demoMet /视图/脚本/

虽然设置了视图文件路径,但它在默认脚本文件夹中搜索

2 个答案:

答案 0 :(得分:0)

也许你可以试试这个:

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);
}

答案 1 :(得分:0)

将_init函数添加到主应用程序Bootatrp.php文件中!

<强> 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");

}