【问题标题】:Zend Framework class not loading in UbuntuZend Framework 类未在 Ubuntu 中加载
【发布时间】:2015-09-10 18:42:03
【问题描述】:

我已将我的 Zend Framework 应用程序移植到不同的服务器。这是一个 Zend Framework 应用程序版本2.3.*

现在访问此网址http://calendar.app/calendar 时出现以下错误:

Fatal error: Class 'Calendar\Controller\CalendarController' not found in /home/vagrant/Code/calendar/vendor/zendframework/zendframework/library/Zend/ServiceManager/AbstractPluginManager.php on line 170

我的 CalendarControler 位于我的日历模块中,该模块的加载方式类似于

return array(
    'controllers' => array(
    'invokables' => array(
        'Calendar' => 'Calendar\Controller\CalendarController',
    ),
),
'router' => array(
    'routes' => array(
        'calendar' => array(
            'type'    => 'Literal',
            'options' => array(
                'route' => '/calendar',
                'defaults' => array(
                    'controller' => 'calendar',
                    'action'     => 'index',
                ),
            ),
        ),
    ),
),
'view_manager' => array(
    'template_path_stack' => array(
        __DIR__ . '/../view',
    ),
),

);

我试过了

composer clear-cache composer dump-autoload

但这没有帮助。 我该如何解决这个问题。

【问题讨论】:

  • Calendar\Controller\CalendarController 的斜线方向是否正确?我认为你需要提供整个路径
  • 此错误似乎表明以下三件事之一——要么您的路径中没有名为 Calendar/Controller/CalendarController.php 的文件,要么您拥有该文件,但其中定义的类名没有匹配,或者您还没有注册自动加载器。

标签: php zend-framework nginx ubuntu-14.04


【解决方案1】:

您在数组中的Calendar 声明是错误的。为了让 Zend 找到类,您需要在数组中使用全名。

return array(
    'controllers' => array(
    'invokables' => array(
        'Calendar\ControllerCalendar' => 'Calendar\Controller\CalendarController',
    ),
    'alias' => array(
        'Calendar' => 'Calendar\ControllerCalendar',
    ),
),
'router' => array(
    'routes' => array(
        'calendar' => array(
            'type'    => 'Literal',
            'options' => array(
                'route' => '/calendar',
                'defaults' => array(
                    'controller' => 'calendar',
                    'action'     => 'index',
                ),
            ),
        ),
    ),
),
'view_manager' => array(
    'template_path_stack' => array(
        __DIR__ . '/../view',
    ),
),

除了这个错误。如果您的类具有硬依赖关系,或者您在控制器中使用像 $this->getServiceLocator() 这样的服务管理器,请考虑使用控制器工厂。 :)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多