爲什麼我得到這個錯誤,即使我已經添加了所有的類?zf2 - 無法將Zend Db Adapter Adapter服務解析到工廠
無法將服務「Zend \ Db \ Adapter \ Adapter」解析到工廠;你確定你在配置期間提供了它嗎?
這裏是我的Module.php:
namespace Album;
use Album\Model\Album;
use Album\Model\AlbumTable;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
class Module {
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 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);
},
),
);
}
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
}
更新: 文件 - application.config.php:
return [
// Retrieve list of modules used in this application.
'modules' => [
'Zend\Router',
'Zend\Validator',
'Application',
'Album',
'Blog',
],
// These are various options for the listeners attached to the ModuleManager
'module_listener_options' => [
'module_paths' => [
'./module',
'./vendor',
],
'config_glob_paths' => [
// realpath(__DIR__) . '/autoload/{{,*.}global,{,*.}local}.php',
realpath(__DIR__) . '/autoload/{,*.}{global,local}.php',
],
'config_cache_enabled' => false,
// The key used to create the configuration cache file name.
'config_cache_key' => 'application.config.cache',
'module_map_cache_enabled' => false,
// The key used to create the class map cache file name.
'module_map_cache_key' => 'application.module.cache',
// The path in which to cache merged configuration.
'cache_dir' => 'data/cache/',
// 'check_dependencies' => true,
],
];
這可能是與你的application.config.php一個問題...你可以張貼的內容?你使用的是哪個版本的骨架應用程序? –
@PurpleHexagon - 我已經更新了我的application.config.php文件..請檢查 –
您是否將以下答案中的數據庫配置代碼添加到其中一個自動加載的配置文件中?如果是這樣的話? –