【问题标题】:Fatal error: Class 'Zend_Controller_Action' not found致命错误:找不到类“Zend_Controller_Action”
【发布时间】:2023-03-07 16:36:01
【问题描述】:

我找到了一些与此问题密切相关的答案,但我仍然无法解决。 我相信人们会说我的包含路径不正确,但我已经尝试了所有我能找到的解决方案,但无济于事。

这是错误:

Fatal error: Class 'Zend_Controller_Action' not found in /Users/*me*/Sites/*site*/application/controllers/IndexController.php on line 3

这是包含语句:

$newIncludePath = array();
$newIncludePath[] = '.';
$newIncludePath[] = 'include';
$newIncludePath[] = get_include_path();
$newIncludePath[] = '../library';
$newIncludePath[] = '../application/classes/';
$newIncludePath[] = '../application/models/';
$newIncludePath[] = '../application/models/';
$newIncludePath[] = '../application/controllers';
$newIncludePath = implode(PATH_SEPARATOR, $newIncludePath);
set_include_path($newIncludePath);

require_once 'Zend/Controller/Front.php';
require_once 'Zend/Loader.php';

Zend_Loader::registerAutoload();

我已经在论坛上敲了几个小时的键盘。我是zend和php的新手。这东西让我很头疼。我已将控制器明确添加到路径中。我不知道我忽略了什么。

顺便说一句,出于隐私原因,me 和 site 是经过编辑的名称。

我永远感激解决方案。

mjs-编辑:

我注意到我的包含有点不稳定。所以这里是一个重做:

$newIncludePath = array();
$newIncludePath[] = '.';
$newIncludePath[] = get_include_path();
$newIncludePath[] = '../library';
$newIncludePath[] = '../application/classes/';
$newIncludePath[] = '../application/models/';
$newIncludePath[] = '../application/library/';
$newIncludePath = implode(PATH_SEPARATOR, $newIncludePath);
set_include_path($newIncludePath);

var_dump 的输出:

string(148) "../application/controllers:.:.:/Applications/MAMP/bin/php5/lib/php:../library:../application/classes/:../application/models/:../application/library/"

我注意到 Zend/Controller/Action 存在于 ../library 下。所以,我不明白为什么应用程序找不到它。

如果我从 PHPDebug 运行 IndexController,它会返回

string(170) ".:/Users/me/Sites/site:/Applications/Zend/Zend Studio - 7.1.0/plugins/org.zend.php.framework.resource_7.1.0.v20091101-1523/resources/ZendFramework-1/library/" 
Fatal error: Class 'Zend_Controller_Action' not found in /Users/me/Sites/site/application/controllers/IndexController.php on line 5

【问题讨论】:

  • 我这两天一直在努力解决这个问题,但我觉得我离解决方案还差得远。希望有人可以提供比我现在更多的见解。谢谢。

标签: php zend-framework fatal-error include-path


【解决方案1】:

Zend_Appilcation 自动加载器的默认行为是采用类名

Zend_Controller_Action

并将其转换为路径

Zend/Controller/Action.php

然后尝试包含/要求加载类所需的文件。

所以,你可能会遇到两个不同的问题

  1. 您的 PHP 包含路径未指向默认的 Zend 库文件夹,并且尝试包含 Zend/Controller/Action.php 失败。

  2. 自动加载器未正确注册

因此,在您的 IndexController.php 文件中,在类声明上方的全局命名空间区域中添加以下内容

var_dump(get_include_path());

这将输出您的包含路径值。检查包含路径中的每个单独的路径,并确保将 Zend/Controller/Action.php 附加到其中之一解析为 Action.php 文件。如果没有,请采取措施确保存在允许这种情况发生的路径。

(以上假设您使用的是 Zend_Application,它是 Zend 自己的应用程序框架,基于他们自己的 Zend 框架。如果您单独使用组件,可能会更加复杂)

【讨论】:

    【解决方案2】:

    您的包含路径是相对于应用程序根目录的,但文件是在不同的级别(即应用程序/控制器)加载的。因此,所有包含路径现在看起来像 application/controllers/../library 这是不正确的。

    我会通过在我的包含路径中使用绝对路径来解决这个问题。例如,尝试将 ../library 更改为 Users/me/Sites/site/library

    【讨论】:

    • 或者您可以使用realpath(dirname(__FILE__)."/../library") 不将自己绑定到特定主机。
    • 我尝试了所有建议,但均未成功。最初在哪里设置包含路径?我问是因为“../application/controllers:”是从“get_include_path()”中检索到的第一个条目。并且 PHP Debug 报告那里没有找到 zend_controller_action。也许某处的 ini 文件有问题?
    猜你喜欢
    • 2014-10-03
    • 1970-01-01
    • 2011-09-08
    • 2011-12-17
    • 2018-12-21
    • 2012-11-21
    • 2015-03-20
    • 2015-03-28
    • 2014-03-13
    相关资源
    最近更新 更多