Zend 框架控制器动作助手

发布于 2024-09-04 20:53:12 字数 3041 浏览 10 评论 0原文

添加操作助手类后出现致命错误。我正在尝试加载与调用的布局相对应的布局。以下是我的代码片段:

首先,我在 application/controller/helpers 下添加了一个帮助器类:

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

    }

}

然后我在 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());
}

以下是我的 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

运行此代码时,我收到以下错误:

警告: 包括(Zend\Controller\Action\Helper\LayoutLoader.php) [function.include]:打开失败 流:没有这样的文件或目录 D:\个人\proj\renovate\library\Zend\Loader.php 第83行

警告:include() [函数.include]: 打开失败 'Zend\Controller\Action\Helper\LayoutLoader.php' 纳入 (include_path='D:\personal\proj\renovate\application/../library;D:\personal\proj\renovate\library;.;C:\php5\pear') 在 D:\个人\proj\renovate\library\Zend\Loader.php 第83行

致命错误:类 'Zend_Controller_Action_Helper_LayoutLoader' 未找到于 D:\个人\proj\renovate\application\Bootstrap.php 第 33 行

,请告诉我,我该如何解决这个问题。我是 Zend 框架的初学者。

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:

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:

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:

[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

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

Fatal error: Class
'Zend_Controller_Action_Helper_LayoutLoader'
not found in
D:\personal\proj\renovate\application\Bootstrap.php
on line 33

Kindly let me know, how can i come out from this issue. I am beginner in Zend Framework.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烟火散人牵绊 2024-09-11 20:53:12

似乎您的 include_path 无效

请尝试将其插入到 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))));

这适用于如下目录结构:

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

Seems like you have invalid include_path

Try insert this in the 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
烟酉 2024-09-11 20:53:12

我认为包含路径是有效的。以下是我的index.php

定义应用程序目录的路径

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

定义应用程序环境

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

确保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();

I think include path is valid. Following is my 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

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();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文