【问题标题】:view files are not rendered in zend framework视图文件不在 zend 框架中呈现
【发布时间】:2014-05-15 11:38:26
【问题描述】:

通过以下代码,我设置了布局和查看文件路径。

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

    }


}

但是当我访问 url "http://project.localhost/demoMet/index/" 时。 错误信息

在路径中找不到消息'脚本'index/index.phtml' 项目/应用程序/模块/demoMet/views/scripts/

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

【问题讨论】:

  • 在 bootstrap 下添加这个函数

标签: php templates zend-framework


【解决方案1】:

在您的主应用程序 Bootatrp.php 文件中添加一个 _init 函数!

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

}  

【讨论】:

    【解决方案2】:

    也许你可以试试这个:

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

    【讨论】:

      猜你喜欢
      • 2011-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-23
      • 1970-01-01
      相关资源
      最近更新 更多