I am coming across some problems when trying to use ZF2's authentication
services. I have to following Module.php getServiceConfig function:

<?php
public function getServiceConfig()
{
    return array(
        'factories' => array(
            'Auth\Model\CustomerTable' =>  function($sm) {
                $tableGateway = $sm->get('CustomerTableGateway');
                $table = new CustomerTable($tableGateway);
                return $table;
            },
            'CustomerTableGateway' => function($sm) {
                $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                $resultSetPrototype = new ResultSet();
                $resultSetPrototype->setArrayObjectPrototype(new
Customer()); // prototype pattern implemented.
                return new TableGateway('customer', $dbAdapter, null,
$resultSetPrototype);
            },
            'Auth\Model\AuthStorage' => function($sm){
                return new \Auth\Model\AuthStorage('jamietech');  
            },
            'AuthService' => function($sm) {
                $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                $dbTableAuthAdapter  = new DbTableAuthAdapter($dbAdapter, 
                                          'customer','username','password');

                $authService = new AuthenticationService();
                $authService->setAdapter($dbTableAuthAdapter);
               
$authService->setStorage($sm->get('Auth\Model\AuthStorage'));

                return $authService;
            },
        ),
    );
}
The AuthStorage factory simply creates a new AuthStorage for us to keep
track of the rememberMe function I have, and the AuthService factory creates
a new Authentication Service for us. I can't see anything that I have done
wrong but when running the following code in the AuthController.php:

    <?php
    public function loginAction()
{
    //if already login, redirect to success page 

        if ($this->getAuthService()->hasIdentity()){
        return $this->redirect()->toRoute('success');
        }

        $form = new LoginForm();

    return array(
        'form'      => $form,
        'messages'  => $this->flashmessenger()->getMessages()
    );
}

    public function logoutAction()
{
    $this->getSessionStorage()->forgetMe();
            $this->getAuthService()->clearIdentity();
            $this->flashmessenger()->addMessage("You have logged out
successfully.");

            return $this->redirect()->toRoute('auth',
array('action'=>'login'));
}
PHPUnit encounters the following errors when running the PHPUnit command:

1: "testLoginActionCanBeAccessed - Zend\ServiceManager\ServiceManager::get
was unable to fetch or create an instance of Zend\Db\Adapter\Adapter

1: "testLogoutActionCanBeAccessed - session_regenerate_id(): cannot
regenerate session id - headers already sent.

And this error for both login and logout when the -process-isolation command
is run:

"Serialization of closure is not allowed in:
C;\Users-----\AppData\Local\Temp-----

If somebody could help that would be great. I am a ZF noob so try not to be
too harsh.

Thank you! Jamie Mclaughlan



--
View this message in context: 
http://zend-framework-community.634137.n4.nabble.com/ServiceManager-getServiceConfig-problems-unable-to-fetch-or-create-instance-tp4659631.html
Sent from the Zend Framework mailing list archive at Nabble.com.

-- 
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]


Reply via email to