in Uncategorized

An abstract factory could not create an instance of UserTable

Zend Framework 2

This is a second time in a day that I got this error message:

An abstract factory could not create an instance of UserTable

This is what I had to change to fix it (old code):

file: module.config.php

    'di' => array(
        'services' => array(
            // 'StillReCAPTCHA\Model\UserTable' => 'StillReCAPTCHA\Model\UserTable',
            'StillReCAPTCHA\Model\UserMetaTable' => 'StillReCAPTCHA\Model\UserMetaTable',
        )
    ),

then replace it with this (new code):

file: module.php

'factories' => array(
	 'StillReCAPTCHA\Model\UserTable' => function($sm) {
		$tableGateway = $sm->get('UserTableGateway');
		$table = new UserTable($tableGateway);
		return $table;
	},
	 'UserTable' => function($sm) {
		$tableGateway = $sm->get('UserTableGateway');
		$table = new UserTable($tableGateway);
		return $table;
	},
	 'UserTableGateway' => function($sm) {
	 	$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
		$resultSetPrototype = new HydratingResultSet();
		$resultSetPrototype->setObjectPrototype(new User());
		$tableName = 'users';
		return new TableGateway($tableName, $dbAdapter, null, $resultSetPrototype);
	 },
),