ZendFramework 2 中的 ServiceNotFoundException,来自 Rob Allen 的示例 [英] ServiceNotFoundException in ZendFramework 2, example from Rob Allen

查看:21
本文介绍了ZendFramework 2 中的 ServiceNotFoundException,来自 Rob Allen 的示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去几周我一直在关注 ZF2,尤其是 Rob Allen 的'相册' 示例,我创建了示例 DB-'zf2tutorial' 和示例表-'album',当我使用 php-mysql 时,它可以很好地获取所有项目,因此出现问题数据库中的数据.

for the past few weeks I have been following ZF2 especially Rob Allen's 'Album' example , I have created the example DB-'zf2tutorial' and example table-'album', which works fine fetching all the items when I use php-mysql, so problems with the data in the DB.

我的 local.php 看起来像这样config.autoload/local.php:

My local.php looks like this config.autoload/local.php:

return array(
    'db' => array
    (
        'driver'         => "Pdo",
        'dsn'            => "mysql:dbname=zf2tutorial;hostname=localhost",
        'username'       => "user", //here I added my valid username 
        'password'       => "password", //here I added my valid password 
        'driver_options' => array
        (
            PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'"
        ),
    ),
);

模块.php**模块/相册/Model.php

Module.php **module/Album/Model.php

<?php
namespace Album;

use Album\Model\AlbumTable;

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 getServiceConfiguration() 
    {
        return array(

            'factories' => array(

                'album-table' => function($sm) //also tried this 'Album\Model\AlbumTable' =>  function($sm)
                {
                    $dbAdapter = $sm->get('db-adapter');//also tried this $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                    $table = new AlbumTable($dbAdapter);
                    return $table;
                },
            ),
        );
    }  
}

我只是想检查 zf2turorial/album 是否有效它确实抛出了这个错误,类似于 this 在 stackoverlow 中发布.

I just wanted to check whether the zf2turorial/album works or not it does throw this error which is similar to this post here in stackoverlow.

它抛出的错误是:附加信息:Zend\ServiceManager\Exception\ServiceNotFoundException

File:
..\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php:392
Message:
Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for Album\Model\AlbumTable

我也遵循了 ZF2 Beta 5 教程,但仍然遇到此问题.如果有人有解决方案,请与我们分享.

I have followed ZF2 Beta 5 tutorial as well, but still encountering this problem. In case if anyone has a solution, please do share with us.

谢谢

推荐答案

似乎有人忘记更新 zf2 中的最新更改.

seems like somebody has forgotten to update the newest changes in zf2.

解决办法:

文件 module/Album/Module.php 必须包含以下内容:

the file module/Album/Module.php has to contain this content:

<?php

namespace Album;

use Album\Model\AlbumTable;
use Zend\ModuleManager\Feature\ServiceProviderInterface;

class Module implements ServiceProviderInterface

然后你必须重命名

public function getServiceConfig()

public function getServiceConfiguration()

这篇关于ZendFramework 2 中的 ServiceNotFoundException,来自 Rob Allen 的示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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