Wednesday, June 27, 2012

ZF2-Tutorial ServiceManager Exceptions


I started my adventure learning Zend Framework 2  today. I decided to begin with Rob Allen’s tutorial at  http://akrabat.com/zend-framework-2-tutorial/. I set up my PC with XAMPP 1.7.7 and installed Zend Framework 2 beta 4. I made excellent progress with the tutorial until I reached "Listing albums" using http://zf2-tutorial.localhost/album and I kept receiving the following errors:


Zend\ServiceManager\Exception\ServiceNotCreatedException

Zend\ServiceManager\ServiceManager::get was unable to fetch or create an                  instance for album-table

Zend\ServiceManager\Exception\ServiceNotCreatedException

Zend\ServiceManager\ServiceManager::get was unable to fetch or create an                  instance for db-adapter

Zend\Db\Adapter\Exception\InvalidArgumentException

The supplied or instantiated driver object does not implement                             Zend\Db\Adapter\Driver\DriverInterface

It appears that my application is not instantiating my PDO driver correctly. I investigated the function getServiceConfiguration() in module/Application/Module.php:
public function getServiceConfiguration()
{
   return array(
      'factories' => array(
         'db-adapter' => function($sm) {
            $config = $sm->get('config');
            $config = $config['db'];
            $dbAdapter = new DbAdapter($config);
            return $dbAdapter;
         }, 
      ), 
   );
}
The factory is not passing the 'db' array from the merged configurations correctly. I fixed the exceptions by changing the getServiceConfiguration() to:

public function getServiceConfiguration()
{
   return array(
      'factories' => array(
         'db-adapter' => function($sm) {
            $config = $sm->get('config');
            $config = $config['db'];
            $config = array(
               'driver'         => $config['driver'], 
               'dsn'            => $config['dsn'], 
               'username'       => $config['username'], 
               'password'       => $config['password'], 
               'driver_options' => $config['driver_options']
            );
            $dbAdapter = new DbAdapter($config);
            return $dbAdapter;
         }, 
      ), 
   );
}

Now I also downloaded Rob Allen's github repo of the tutorial, and the repo threw the same exceptions as my original getServiceConfiguration(). Am I doing something wrong? Is my solution correct? How could I create a more elegant solution?

Tuesday, June 26, 2012

Inception


I had an idea.

I, unfortunately, am very picky about how I execute my ideas. I wanted to create a blog about adapting video games for the disabled. My first step would be to create a website. This cannot be just any website; I had to own it. The website must be mine. I wanted 100% control, and not some cookie-cutter website would do.

I decided to create my own blogging and article content management system with PHP.

How was I going to do this?

I researched many different PHP frameworks. In the end, I decided to start with a framework that wasn't yet complete. I chose to use Zend Framework 2, even though it is still in beta.

This is the diary of my adventure to create supershaun.net!