php - 模块(专辑)无法初始化zf2教程

标签 php zend-framework2

我正在学习 zend 框架 2 教程应用程序。我已经设置了我的相册模块目录如下:

enter image description here

当我启动我的 MAMP 服务器时,我遇到了一个错误, fatal error :未捕获的异常“Zend\ModuleManager\Exception\RuntimeException”和消息“无法初始化模块(相册)”。

如果我从以下代码(在 /config/application.config.php 中)注释掉 Album 模块:

'modules' => array(
    'Application',
    'Album',
),

我进入骨架应用程序主页。 这是我的 /module/Album/Module.php 代码:

namespace Album;

use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
use Zend\ModuleManager\Feature\ConfigProviderInterface;
use Album\Model\Album;
use Album\Model\AlbumTable;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;

class Module implements AutoloaderProviderInterface, ConfigProviderInterface {

public function getAutoloaderConfig() {
    return array(
        ’Zend\Loader\ClassMapAutoloader’ => array(
            __DIR__ . ’/autoload_classmap.php’,
        ),
        ’Zend\Loader\StandardAutoloader’ => array( ’namespaces’ => array(
            __NAMESPACE__ => __DIR__ . ’/src/’ . __NAMESPACE__,
            ),
        ), 
    );
}

public function getConfig() {
    return include __DIR__ . ’/config/module.config.php’; 
}

public function getServiceConfig() {
    return array(
        ’factories’ => array(
            ’Album\Model\AlbumTable’ => function($sm) { 
                $tableGateway = $sm->get(’AlbumTableGateway’); 
                $table = new AlbumTable($tableGateway);
                return $table;
            },
            ’AlbumTableGateway’ => function ($sm) {
                $dbAdapter = $sm->get(’Zend\Db\Adapter\Adapter’);
                $resultSetPrototype = new ResultSet(); $resultSetPrototype->setArrayObjectPrototype(new Album());
                return new TableGateway(’album’, $dbAdapter, null, $resultSetPrototype);
            }, 
        ),
    ); 
}
}

这是我在 /module/Album/config/ 中的 module.config.php 代码:

return array(
’controllers’ => array(
    ’invokables’ => array(
        ’Album\Controller\Album’ => ’Album\Controller\AlbumController’,
    ),
),

’view_manager’ => array( 
    ’template_path_stack’ => array(
        ’album’ => __DIR__ . ’/../view’,
    ),
),

'router' => array(
    'routes' => array(
        'album' => array(
            'type' => 'segment',
            'options' => array(
                'route' => '/album[/][:action][/:id]',
                'constraints' => array(
                    'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'id' => '[0-9]+',
                ),
                'defaults' => array(
                    'controller' => 'Album\Controller\Album',
                    'action' => 'index',
                ),
            ),
        ),
    ),
),'
);

我读过一些遇到过类似情况的人,但他们的问题是由于拼写错误/错误命名的类。我没有发现我的代码有任何问题(甚至直接从教程中复制/粘贴)。

有人可以给我一些建议吗?

谢谢

最佳答案

我有同样的问题,解决方案是用 <?php 开始每个 .php 文件 这在教程中并不清楚(如果您只是从那里复制代码),这就是我遇到相同异常的原因。

关于php - 模块(专辑)无法初始化zf2教程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24602455/

相关文章:

php - PDO : Error not caught when executing prepared statement 故障排除

php - GeSHi 网络代码编辑器

php - ZF2 中的寄存器库

PHP 不会渲染 - Python Tornado

php - .htaccess 带有 MVC 应用程序 Controller 名称的重定向 url

zend-framework - Zend Framework 2 Doctrine ORM 身份验证

php - 在 ZF2 中发送带有附件的电子邮件

.htaccess - 使用 #! 重定向 URL动态内容

php - 授予 bjyauthorize 从 CLI 运行 ZF2 的 mvc 应用程序的权限

javascript - Woocommerce 3 中的自定义加减数量按钮