我正在通過zend框架2教程應用程序工作。我已經建立了我的相冊模塊目錄如下:模塊(專輯)無法初始化zf2教程
我遇到了一個錯誤,當我開始我的MAMP服務器,Fatal error: Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (Album) could not be initialized.'
如果我從下面的代碼註釋掉Album
模塊(在/config/application.config.php
):
'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',
),
),
),
),
),'
);
我已經通過誰已經在類似的情況下,跑了幾個人看,但他們的問題是由於拼錯/錯誤命名的類。我沒有看到我的代碼有任何問題(甚至直接從教程複製/粘貼)。
有人可以給我一些建議嗎?
感謝
嘗試更新'composer'文件。 –
@KunalDethe在添加一些東西到作曲家文件或運行作曲家更新命令? –
我創建了一個新的骨架應用程序,再次嘗試這個,我有同樣的問題。教程中有什麼錯誤嗎?我會很驚訝,但我真的不知道它可能是什麼 –