Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
450 views
in Technique[技术] by (71.8m points)

zend framework2 - ServiceNotFoundException in ZendFramework 2, example from Rob Allen

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.

My local.php looks like this con?g.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'"
        ),
    ),
);

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

<?php
namespace Album;

use AlbumModelAlbumTable;

class Module 
{
    public function getAutoloaderConfig() 
    {
        return array(
            'ZendLoaderClassMapAutoloader' => array(
                __DIR__ . '/autoload_classmap.php',
            ),
            'ZendLoaderStandardAutoloader' => 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 'AlbumModelAlbumTable' =>  function($sm)
                {
                    $dbAdapter = $sm->get('db-adapter');//also tried this $dbAdapter = $sm->get('ZendDbAdapterAdapter');
                    $table = new AlbumTable($dbAdapter);
                    return $table;
                },
            ),
        );
    }  
}

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.

The error which it is throwing is: Additional information: ZendServiceManagerExceptionServiceNotFoundException

File:
..vendorzendframeworkzendframeworklibraryendServiceManagerServiceManager.php:392
Message:
ZendServiceManagerServiceManager::get was unable to fetch or create an instance for AlbumModelAlbumTable

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.

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

the solution:

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

<?php

namespace Album;

use AlbumModelAlbumTable;
use ZendModuleManagerFeatureServiceProviderInterface;

class Module implements ServiceProviderInterface

then you have to rename

public function getServiceConfig()

to

public function getServiceConfiguration()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...