Quantcast

Dependincy Injector... can't find instance

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Dependincy Injector... can't find instance

poashoas
File:
C:\Program Files\Zend\Apache2\htdocs\vendor\ZF2\library\Zend\ServiceManager\ServiceManager.php:843

Message:
An abstract factory could not create an instance of logineventauthentication(alias: Login\Event\Authentication).

------------------------------------------------------------------------------------------------------

Module.php

namespace Login;

use Zend\ModuleManager\Feature\AutoloaderProviderInterface,
    Zend\EventManager\StaticEventManager;

class Module implements AutoloaderProviderInterface
{
    public function init()
    {
        $events = StaticEventManager::getInstance();
        $events->attach('Zend\Mvc\Controller\AbstractActionController', 'dispatch', array($this, 'loadConfiguration'), 100);
    }

    public function getConfig()
    {
        return include __DIR__ . '/config/module.config.php';
    }

    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 loadConfiguration($event)
    {
      $di = $event->getTarget()->getServiceLocator();
     $auth = $di->get('Login\Event\Authentication');
     return $auth->preDispatch($event);
    }
}



I am a big idiot with this stuff, can anyone help me rewriting this stuff  below??????
I already checked the namespaces, my debugger tells me the instance logineventauthentication doesn't appear in the list of instances

<?php
return array(
    'di' => array(
        'allowed_controllers' => array(
             'Login\Controller\FormController'
             ),
        'instance' => array(
            'alias' => array(
                'login' => 'Login\Controller\FormController'
            ),
            'login' => array(
                'parameters' => array(
                    'broker' => 'Zend\Mvc\Controller\PluginBroker'
                )
            ),
            'Login\Event\Authentication' => array(
                'parameters' => array(
                    'userAuthenticationPlugin' => 'Login\Controller\Plugin\UserAuthentication',
                    'aclClass'                 => 'Login\Acl\Acl'
                )
            ),
            'Login\Acl\Acl' => array(
                'parameters' => array(
                    'config' => include __DIR__ . '/acl.config.php'
                )
            ),
            'Login\Controller\Plugin\UserAuthentication' => array(
                'parameters' => array(
                    'authAdapter' => 'Zend\Authentication\Adapter\DbTable'
                )
            ),
            'Zend\Authentication\Adapter\DbTable' => array(
                'parameters' => array(
                    'zendDb' => 'Zend\Db\Adapter\Adapter',
                    'tableName' => 'users',
                    'identityColumn' => 'email',
                    'credentialColumn' => 'password',
                    'credentialTreatment' => 'SHA1(CONCAT(?, "secretKey"))'
                )
            ),
        'Zend\Db\Adapter\Adapter' => array(
            'parameters' => array(
               'driver'    => 'pdo',
               'dsn'       => 'mysql:dbname=mydatabase;host=localhost',
               'database'  => 'mydatabase',
               'username'  => 'root',
               'password'  => '',
               'hostname'  => 'localhost',
            )
        ),

        'Zend\Mvc\Controller\PluginLoader' => array(
                'parameters' => array(
                    'map' => array(
                        'userAuthentication' => 'Login\Controller\Plugin\UserAuthentication'
                    )
                )
            ),
            'Zend\View\PhpRenderer' => array(
                'parameters' => array(
                    'options' => array(
                        'script_paths' => array(
                            'user' => __DIR__ . '/../views'
                        )
                    )
                )
            )
        )
    ),
    'router' => array(
      'routes' => array(
        'login' => array(
            'type' => 'Zend\Mvc\Router\Http\Literal',
            'options' => array(
                'route'    => '/login',
                'defaults' => array(
                    'controller' => 'Login\Controller\Form',
                    'action'     => 'index',
                ),
            ),
        ),
    )),
);
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Dependincy Injector... can't find instance

developer10
I'm a ZF newbie, FYI.

I think I read somewhere on this mail-list O'Phinney wrote there's no init() for ZF2 controllers? Could that be the source of your problem or I picked up something else?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Dependincy Injector... can't find instance

Marco Pivetta
In reply to this post by poashoas
Always check $e->getPrevious() on exceptions.

The skeleton application already handles that in the error view.
Otherwise, use a try-catch block like that

try {
    // buggy block
} catch (\Exception $e) {
    do {
        echo $e->getMessage();
    } while ($e = $e->getPrevious);
}

Marco Pivetta

http://twitter.com/Ocramius

http://marco-pivetta.com



On 21 September 2012 01:43, poashoas <[hidden email]> wrote:

> File:
> C:\Program
>
> Files\Zend\Apache2\htdocs\vendor\ZF2\library\Zend\ServiceManager\ServiceManager.php:843
>
> Message:
> An abstract factory could not create an instance of
> logineventauthentication(alias: Login\Event\Authentication).
>
>
> ------------------------------------------------------------------------------------------------------
>
> *Module.php*
>
> namespace Login;
>
> use Zend\ModuleManager\Feature\AutoloaderProviderInterface,
>     Zend\EventManager\StaticEventManager;
>
> class Module implements AutoloaderProviderInterface
> {
>     public function init()
>     {
>         $events = StaticEventManager::getInstance();
>         $events->attach('Zend\Mvc\Controller\AbstractActionController',
> 'dispatch', array($this, 'loadConfiguration'), 100);
>     }
>
>     public function getConfig()
>     {
>         return include __DIR__ . '/config/module.config.php';
>     }
>
>     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 loadConfiguration($event)
>     {
>       $di = $event->getTarget()->getServiceLocator();
>      $auth = $di->get('Login\Event\Authentication');
>      return $auth->preDispatch($event);
>     }
> }
>
> <
> http://zend-framework-community.634137.n4.nabble.com/file/n4656989/Untitled-2.jpg
> >
>
> *I am a big idiot with this stuff, can anyone help me rewriting this stuff
> below??????*
> I already checked the namespaces, my debugger tells me the instance
> logineventauthentication doesn't appear in the list of instances
>
> <?php
> return array(
>     'di' => array(
>         'allowed_controllers' => array(
>              'Login\Controller\FormController'
>              ),
>         'instance' => array(
>             'alias' => array(
>                 'login' => 'Login\Controller\FormController'
>             ),
>             'login' => array(
>                 'parameters' => array(
>                     'broker' => 'Zend\Mvc\Controller\PluginBroker'
>                 )
>             ),
>             'Login\Event\Authentication' => array(
>                 'parameters' => array(
>                     'userAuthenticationPlugin' =>
> 'Login\Controller\Plugin\UserAuthentication',
>                     'aclClass'                 => 'Login\Acl\Acl'
>                 )
>             ),
>             'Login\Acl\Acl' => array(
>                 'parameters' => array(
>                     'config' => include __DIR__ . '/acl.config.php'
>                 )
>             ),
>             'Login\Controller\Plugin\UserAuthentication' => array(
>                 'parameters' => array(
>                     'authAdapter' => 'Zend\Authentication\Adapter\DbTable'
>                 )
>             ),
>             'Zend\Authentication\Adapter\DbTable' => array(
>                 'parameters' => array(
>                     'zendDb' => 'Zend\Db\Adapter\Adapter',
>                     'tableName' => 'users',
>                     'identityColumn' => 'email',
>                     'credentialColumn' => 'password',
>                     'credentialTreatment' => 'SHA1(CONCAT(?, "secretKey"))'
>                 )
>             ),
>         'Zend\Db\Adapter\Adapter' => array(
>             'parameters' => array(
>                'driver'    => 'pdo',
>                'dsn'       => 'mysql:dbname=mydatabase;host=localhost',
>                'database'  => 'mydatabase',
>                'username'  => 'root',
>                'password'  => '',
>                'hostname'  => 'localhost',
>             )
>         ),
>
>         'Zend\Mvc\Controller\PluginLoader' => array(
>                 'parameters' => array(
>                     'map' => array(
>                         'userAuthentication' =>
> 'Login\Controller\Plugin\UserAuthentication'
>                     )
>                 )
>             ),
>             'Zend\View\PhpRenderer' => array(
>                 'parameters' => array(
>                     'options' => array(
>                         'script_paths' => array(
>                             'user' => __DIR__ . '/../views'
>                         )
>                     )
>                 )
>             )
>         )
>     ),
>     'router' => array(
>       'routes' => array(
>         'login' => array(
>             'type' => 'Zend\Mvc\Router\Http\Literal',
>             'options' => array(
>                 'route'    => '/login',
>                 'defaults' => array(
>                     'controller' => 'Login\Controller\Form',
>                     'action'     => 'index',
>                 ),
>             ),
>         ),
>     )),
> );
>
>
>
> --
> View this message in context:
> http://zend-framework-community.634137.n4.nabble.com/Dependincy-Injector-can-t-find-instance-tp4656989.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
> --
> List: [hidden email]
> Info: http://framework.zend.com/archives
> Unsubscribe: [hidden email]
>
>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Dependincy Injector... can't find instance

poashoas
In reply to this post by poashoas
Thanks for all the replies

One mistake somewhere in the DI f*cks everything up.
AND,.. I had to make an autoload_classmap, helps a lot
AND, ... I had to refactor some zend classnames and put some dependencies like....:

  'di' => array(
    'allowed_controllers' => array(
      'Login\Controller\FormController',
     ),
    'instance' => array(
      'Zend\Db\Adapter\Adapter' => array(
        'parameters' => array(
          'driver' => 'Zend\Db\Adapter\Driver\Pdo\Pdo',
        ),
      ),
      'Zend\Db\Adapter\Driver\Pdo\Pdo' => array(
        'parameters' => array(
          'connection' => 'Zend\Db\Adapter\Driver\Pdo\Connection',
        ),
      ),
      'Zend\Db\Adapter\Driver\Pdo\Connection' => array(
        'parameters' => array(
          'connectionParameters' => array(
            'dsn'            => "mysql:dbname=" . $dbParams['database'] . ";host=" . $dbParams['hostname'],
            'username'       => $dbParams['username'],
            'password'       => $dbParams['password'],
            'driver_options' => array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''),
          ),
        ),
      ),
    )
  )
Loading...