我正在关注本教程,但收到错误 Zend\ServiceManager\ServiceManager::get is unable to fetch or create an instance for Zend\Db\Adapter\Adapter
我已经谷歌搜索并尝试了所有解决方案,但没有运气。请帮助pppp我很沮丧:|
仅供参考:我正在使用这个骨架https://github.com/zendframework/ZendSkeletonApplication去。我没有安装zend。
module.php 命名空间相册;
// Add these import statements:
use Album\Model\Album;
use Album\Model\AlbumTable;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\Tabl`enter code here`eGateway;
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 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);
},
),
);
}
}
全局.php
return array(
'db' => array(
'driver' => 'Pdo',
'dsn' => 'mysql:dbname=aaa;host=aaa',
'driver_options' => array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''
),
),
'service_manager' => array(
'factories' => array(
'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory',
),
),
);
我阅读并尝试了这些: ZF2 - get 无法获取或创建 getAlbumTable 的实例
ZendFramework 2 中的 ServiceNotFoundException,来自 Rob Allen 的示例
总是以不明确的方式结束