请帮助我 Zend\ServiceManager\ServiceManager::get 无法为 Zend\Db\Adapter\Adapter 获取或创建实例 [英] please help me Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for Zend\Db\Adapter\Adapter

查看:24
本文介绍了请帮助我 Zend\ServiceManager\ServiceManager::get 无法为 Zend\Db\Adapter\Adapter 获取或创建实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习本教程,但出现错误 Zend\ServiceManager\ServiceManager::get 无法为 Zend\Db\Adapter\Adapter 获取或创建实例

i'm following this tutorial but got error Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for Zend\Db\Adapter\Adapter

我已经谷歌搜索并尝试了所有解决方案,但没有运气.请帮助pppp我很沮丧:|

i've googling and tried all solution but no luck. please helppppp i'm depressed :|

仅供参考:我正在使用这个骨架 https://github.com/zendframework/ZendSkeletonApplication去.我没有安装zend.

FYI : i'm using this skeleton https://github.com/zendframework/ZendSkeletonApplication and go. i didn't install zend.

模块.php命名空间相册;

module.php namespace Album;

// 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);
             },
         ),
     );
 }

}

global.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 创建一个实例

i read & tried these : ZF2 - get was unable to fetch or create an instance for getAlbumTable

ZendFramework 2 中的 ServiceNotFoundException,来自 Rob Allen 的示例

总是不清晰

推荐答案

这是因为 DB 配置错误,要解决这个问题,您必须在 main config 文件夹中的 global.php 中配置 DB.代码如下,复制粘贴和只需更改数据库名称和密码,

This is because of DB configuration error, to solve this you have to configure DB in global.php in main config folder.Code is given below, Copy paste and Just change the db name and password,

return array(
    'db' => array(
        'driver'         => 'Pdo',
        'dsn'            => 'mysql:dbname=zf2tutorial;host=localhost',
        'driver_options' => array(
            PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''
        ),
        'username'       => 'root',
        'password'       => ''
    ),
    'service_manager' => array(
        'factories' => array(
            'Zend\Db\Adapter\Adapter'
                    => 'Zend\Db\Adapter\AdapterServiceFactory',
        ),
    ),
);

这篇关于请帮助我 Zend\ServiceManager\ServiceManager::get 无法为 Zend\Db\Adapter\Adapter 获取或创建实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆