Unable to resolve service "Zend\Db\Adapter\AdapterInterface"

For programming and general questions on Zend Framework

Unable to resolve service "Zend\Db\Adapter\AdapterInterface"

Postby nach4528 on Wed Oct 18, 2017 11:46 am

Hi,

I'm starting with Zend 3, I downloaded the github/zendframework/ZendSkeletonApplication from github but when I try to show SKELETON-APPLICATION/public/album I get the following error:

An error occurred
An error occurred during execution; please try again later.
Additional information:
Zend\ServiceManager\Exception\ServiceNotFoundException
File:
C:\xampp2\htdocs\dev\nacho\SKELETON-APPLICATION\vendor\zendframework\zend-servicemanager\src\ServiceManager.php:681
Message:
Unable to resolve service "Zend\Db\Adapter\AdapterInterface" to a factory; are you certain you provided it during configuration?
Stack trace:
#0 C:\xampp2\htdocs\dev\nacho\SKELETON-APPLICATION\vendor\zendframework\zend-servicemanager\src\ServiceManager.php(757): Zend\ServiceManager\ServiceManager->getFactory('Zend\\Db\\Adapter...')
#1 C:\xampp2\htdocs\dev\nacho\SKELETON-APPLICATION\vendor\zendframework\zend-servicemanager\src\ServiceManager.php(200): Zend\ServiceManager\ServiceManager->doCreate('Zend\\Db\\Adapter...')
#2 C:\xampp2\htdocs\dev\nacho\SKELETON-APPLICATION\module\Album\Module.php(29): Zend\ServiceManager\ServiceManager->get('Zend\\Db\\Adapter...')
#3 C:\xampp2\htdocs\dev\nacho\SKELETON-APPLICATION\vendor\zendframework\zend-servicemanager\src\ServiceManager.php(758): Album\Module->Album\{closure}(Object(Zend\ServiceManager\ServiceManager), 'Model\\AlbumTabl...', NULL)
#4 C:\xampp2\htdocs\dev\nacho\SKELETON-APPLICATION\vendor\zendframework\zend-servicemanager\src\ServiceManager.php(200): Zend\ServiceManager\ServiceManager->doCreate('Model\\AlbumTabl...')
#5 C:\xampp2\htdocs\dev\nacho\SKELETON-APPLICATION\module\Album\Module.php(24): Zend\ServiceManager\ServiceManager->get('Model\\AlbumTabl...')
#6 C:\xampp2\htdocs\dev\nacho\SKELETON-APPLICATION\vendor\zendframework\zend-servicemanager\src\ServiceManager.php(758): Album\Module->Album\{closure}(Object(Zend\ServiceManager\ServiceManager), 'Album\\Model\\Alb...', NULL)
#7 C:\xampp2\htdocs\dev\nacho\SKELETON-APPLICATION\vendor\zendframework\zend-servicemanager\src\ServiceManager.php(200): Zend\ServiceManager\ServiceManager->doCreate('Album\\Model\\Alb...')
#8 C:\xampp2\htdocs\dev\nacho\SKELETON-APPLICATION\module\Album\Module.php(45): Zend\ServiceManager\ServiceManager->get('Album\\Model\\Alb...')
#9 C:\xampp2\htdocs\dev\nacho\SKELETON-APPLICATION\vendor\zendframework\zend-servicemanager\src\ServiceManager.php(758): Album\Module->Album\{closure}(Object(Zend\ServiceManager\ServiceManager), 'Album\\Controlle...', NULL)
#10 C:\xampp2\htdocs\dev\nacho\SKELETON-APPLICATION\vendor\zendframework\zend-servicemanager\src\ServiceManager.php(200): Zend\ServiceManager\ServiceManager->doCreate('Album\\Controlle...')
#11 C:\xampp2\htdocs\dev\nacho\SKELETON-APPLICATION\vendor\zendframework\zend-servicemanager\src\AbstractPluginManager.php(141): Zend\ServiceManager\ServiceManager->get('Album\\Controlle...')
#12 C:\xampp2\htdocs\dev\nacho\SKELETON-APPLICATION\vendor\zendframework\zend-mvc\src\DispatchListener.php(95): Zend\ServiceManager\AbstractPluginManager->get('Album\\Controlle...')
#13 C:\xampp2\htdocs\dev\nacho\SKELETON-APPLICATION\vendor\zendframework\zend-eventmanager\src\EventManager.php(322): Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent))
#14 C:\xampp2\htdocs\dev\nacho\SKELETON-APPLICATION\vendor\zendframework\zend-eventmanager\src\EventManager.php(179): Zend\EventManager\EventManager->triggerListeners(Object(Zend\Mvc\MvcEvent), Object(Closure))
#15 C:\xampp2\htdocs\dev\nacho\SKELETON-APPLICATION\vendor\zendframework\zend-mvc\src\Application.php(332): Zend\EventManager\EventManager->triggerEventUntil(Object(Closure), Object(Zend\Mvc\MvcEvent))
#16 C:\xampp2\htdocs\dev\nacho\SKELETON-APPLICATION\public\index.php(40): Zend\Mvc\Application->run()
#17 {main}



Could you help me please?
Thanks!
nach4528
 
Posts: 5
Joined: Wed Oct 18, 2017 11:39 am

Re: Unable to resolve service "Zend\Db\Adapter\AdapterInterf

Postby nach4528 on Wed Oct 18, 2017 12:28 pm

I downloaded the project xtreamwayz/zf3-album-tutorial from github not zendframework/ZendSkeletonApplication, sorry!
nach4528
 
Posts: 5
Joined: Wed Oct 18, 2017 11:39 am

Re: Unable to resolve service "Zend\Db\Adapter\AdapterInterf

Postby nach4528 on Thu Oct 19, 2017 7:21 am

Hi,

Forget my previous posts! I followed the zend 3 tutorial and got this error:

A 404 error occurred
Page not found.
The requested controller could not be mapped to an existing controller class.

Controller:
Controller\AlbumController (resolves to invalid controller class or alias: Controller\AlbumController)
No Exception available

The solution:

File module\Album\config\module.config.php

<?php
use Zend\Router\Http\Segment;

return [

'router' => [
'routes' => [
'album' => [
'type' => Segment::class,
'options' => [
'route' => '/album[/:action[/:id]]',
'constraints' => [
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
],
'defaults' => [
'controller' => Album\Controller\AlbumController::class, // <-------------------------- I added Album\ (missing in the tutorial)
'action' => 'index',
],
],
],
],
],


'view_manager' => [
'template_path_stack' => [
'album' => __DIR__ . '/../view',
],
],
];

and It's working!

Thanks!
nach4528
 
Posts: 5
Joined: Wed Oct 18, 2017 11:39 am

Re: Unable to resolve service "Zend\Db\Adapter\AdapterInterf

Postby nach4528 on Thu Oct 19, 2017 9:50 am

I finished zend 3 tutorial and evething worked!

In the last point "Ensuring that the home page displays the list of albums" specify the default controller for home page without "Controller\" before "AlbumController::class"

File module\Album\config\module.config.php

Code: Select all
'router' => [
        'routes' => [
            'home' => [
                'type' => \Zend\Router\Http\Literal::class,
                'options' => [
                    'route' => '/',
                    'defaults' => [
                        'controller' => AlbumController::class,  // It works without Album\Controller\, doesn't work with Controller\
                        'action' => 'index',
                    ],
                ],
            ],
            'album' => [
                'type'    => Segment::class,
                'options' => [
                    'route' => '/album[/:action[/:id]]',
                    'constraints' => [
                        'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                        'id'     => '[0-9]+',
                    ],
                    'defaults' => [
                        'controller' => AlbumController::class, // It works without Album\Controller\, doesn't work with Controller\ 
                        'action'     => 'index',
                    ],
                ],
            ],
        ],
    ],


If helps someone...

Thanks!
nach4528
 
Posts: 5
Joined: Wed Oct 18, 2017 11:39 am


Return to Zend Framework

Who is online

Users browsing this forum: No registered users and 3 guests