我正在按照骨架应用程序教程在1&1共享托管站点上设置Zend Framework 2,并且我遇到应用程序模块未加载的问题:
Fatal error: Uncaught exception 'ZendModuleManagerExceptionRuntimeException' with message
'Module (Application) could not be initialized.' in /homepages/etc/etc/etc/zendskeletonapplication-master/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php:175
我发现有人有同样的错误,但他们只在单元测试中得到它,我在加载网站本身时得到它。尽管如此,我已经尝试更改module_paths
设置,但错误没有改变。
我猜这是模块加载的某种特定问题。为了做到这一点,我已经添加了一个.htaccess
与这些设置(设置服务器使用PHP 5.4.16,尽管提到"php6"):
AddHandler x-mapp-php6 .php
AddType x-mapp-php6 .php
我认为这不是一个问题。当你在模块中设置了错误的内容时,通常会出现此问题。
检查以下文件,确保它们存在并正确设置。看起来你正在使用框架应用教程,所以请确保以下文件完全匹配:
/模块/应用程序/Module.php
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Application;
use ZendMvcModuleRouteListener;
use ZendMvcMvcEvent;
class Module
{
public function onBootstrap(MvcEvent $e)
{
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
}
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
public function getAutoloaderConfig()
{
return array(
'ZendLoaderStandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
}
/模块/应用程序/配置/module.config.php
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
return array(
'router' => array(
'routes' => array(
'home' => array(
'type' => 'ZendMvcRouterHttpLiteral',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'ApplicationControllerIndex',
'action' => 'index',
),
),
),
// The following is a route to simplify getting started creating
// new controllers and actions without needing to create a new
// module. Simply drop new controllers in, and you can access them
// using the path /application/:controller/:action
'application' => array(
'type' => 'Literal',
'options' => array(
'route' => '/application',
'defaults' => array(
'__NAMESPACE__' => 'ApplicationController',
'controller' => 'Index',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:controller[/:action]]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
),
),
),
),
),
),
),
'service_manager' => array(
'abstract_factories' => array(
'ZendCacheServiceStorageCacheAbstractServiceFactory',
'ZendLogLoggerAbstractServiceFactory',
),
'aliases' => array(
'translator' => 'MvcTranslator',
),
),
'translator' => array(
'locale' => 'en_US',
'translation_file_patterns' => array(
array(
'type' => 'gettext',
'base_dir' => __DIR__ . '/../language',
'pattern' => '%s.mo',
),
),
),
'controllers' => array(
'invokables' => array(
'ApplicationControllerIndex' => 'ApplicationControllerIndexController'
),
),
'view_manager' => array(
'display_not_found_reason' => true,
'display_exceptions' => true,
'doctype' => 'HTML5',
'not_found_template' => 'error/404',
'exception_template' => 'error/index',
'template_map' => array(
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
'template_path_stack' => array(
__DIR__ . '/../view',
),
),
);