简体   繁体   English

Zend框架控制器动作助手

[英]Zend framework controller action helper

I am getting fatal error after adding the action helper class. 添加动作帮助程序类后,出现致命错误。 I am trying to load layout corresponding to called layout. 我正在尝试加载与所谓的布局相对应的布局。 Following is my code snippet: 以下是我的代码段:

First of all i added a helper class under application/controller/helpers: 首先,我在application / controller / helpers下添加了一个helper类:

class Zend_Controller_Action_Helper_Layout extends Zend_Controller_Action_Helper_Abstract {

public $pluginLoader;


public function __construct() 
{
    // TODO Auto-generated Constructor
    $this->pluginLoader = new Zend_Loader_PluginLoader ();
}


public function preDispatch()
{
        $bootstrap = $this->getActionController()->getInvokeArg('bootstrap');
        $config = $bootstrap->getOptions();
        $module = $this->getRequest()->getModuleName();
        if (isset($config[$module]['resources']['layout']['layout'])) {
            $layoutScript = $config[$module]['resources']['layout']['layout'];
            $this->getActionController()->getHelper('layout')->setLayout($layoutScript);
        }

    }

}

Then i added a loader in bootstrap.php: 然后我在bootstrap.php中添加了一个加载器:

protected function _initLayoutHelper() {

    $this->bootstrap('frontController');
    Zend_Controller_Action_HelperBroker::addPath(APPLICATION_PATH .'/controllers/helpers');

    $layout = Zend_Controller_Action_HelperBroker::addHelper(new Zend_Controller_Action_Helper_Layout());
}

Following is my application.ini: 以下是我的application.ini:

[production]
autoloaderNamespaces.tree = "Tree_"
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.helperDirectory = APPLICATION_PATH "/controllers/helpers"

resources.modules[] = ""
contact.resources.frontController.defaultControllerName = "index"
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.layout.layout = layout
admin.resources.layout.layout = admin
#admin.resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"

resources.view[] =

[staging : production]

[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

While running this code i am getting following errors: 运行此代码时,出现以下错误:

Warning: include(Zend\\Controller\\Action\\Helper\\LayoutLoader.php) [function.include]: failed to open stream: No such file or directory in D:\\personal\\proj\\renovate\\library\\Zend\\Loader.php on line 83 警告:include(Zend \\ Controller \\ Action \\ Helper \\ LayoutLoader.php)[function.include]:无法打开流:D:\\ personal \\ proj \\ renovate \\ library \\ Zend \\ Loader.php中没有这样的文件或目录83行

Warning: include() [function.include]: Failed opening 'Zend\\Controller\\Action\\Helper\\LayoutLoader.php' for inclusion (include_path='D:\\personal\\proj\\renovate\\application/../library;D:\\personal\\proj\\renovate\\library;.;C:\\php5\\pear') in D:\\personal\\proj\\renovate\\library\\Zend\\Loader.php on line 83 警告:include()[function.include]:无法打开“ Zend \\ Controller \\ Action \\ Helper \\ LayoutLoader.php”进行包含(include_path ='D:\\ personal \\ proj \\ renovate \\ application /../ library; D: \\ personal \\ proj \\ renovate \\ library;。; C:\\ php5 \\ pear')在第83行的D:\\ personal \\ proj \\ renovate \\ library \\ Zend \\ Loader.php中

Fatal error: Class 'Zend_Controller_Action_Helper_LayoutLoader' not found in D:\\personal\\proj\\renovate\\application\\Bootstrap.php on line 33 致命错误:在第33行的D:\\ personal \\ proj \\ renovate \\ application \\ Bootstrap.php中找不到类'Zend_Controller_Action_Helper_LayoutLoader'

Kindly let me know, how can i come out from this issue. 请让我知道,我该如何解决这个问题。 I am beginner in Zend Framework. 我是Zend Framework的初学者。

Seems like you have invalid include_path 好像您有无效的include_path

Try insert this in the index.php: 尝试将其插入index.php中:


define('ROOTDIR', dirname(__FILE__) . DIRECTORY_SEPARATOR);
define('LIBDIR', realpath(ROOTDIR . '../library') . DIRECTORY_SEPARATOR);
set_include_path(implode(PATH_SEPARATOR, array_merge(explode(PATH_SEPARATOR,ini_get('include_path')), array(LIBDIR))));

This works for directory structure like: 这适用于目录结构,例如:

application/
library/
- Zend/
httpdocs/
- index.php

I think include path is valid. 我认为包含路径是有效的。 Following is my index.php 以下是我的index.php

Define path to application directory 定义应用程序目录的路径

defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

Define application environment 定义应用环境

defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'development'));

Ensure library/ is on include_path 确保library/位于include_path

set_include_path(implode(PATH_SEPARATOR, array(realpath(APPLICATION_PATH . '/../library'),get_include_path(),)));

/** Zend_Application */
require_once 'Zend/Application.php'; 

// Create application, bootstrap, and run
$application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
$application->bootstrap()->run();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM