Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Module (album) could not be initialized zf2 tutorial

I am working through the zend framework 2 tutorial application. I have set up my Album Module directory as follows:

enter image description here

I am running into an error when I start my MAMP server, Fatal error: Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (Album) could not be initialized.'

If I comment out the Album module from the following code (in /config/application.config.php):

'modules' => array(
    'Application',
    'Album',
),

I get to the skeleton application homepage. Here is my /module/Album/Module.php code:

namespace Album;

use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
use Zend\ModuleManager\Feature\ConfigProviderInterface;
use Album\Model\Album;
use Album\Model\AlbumTable;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;

class Module implements AutoloaderProviderInterface, ConfigProviderInterface {

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 getConfig() {
    return include __DIR__ . ’/config/module.config.php’; 
}

public function getServiceConfig() {
    return array(
        ’factories’ => array(
            ’Album\Model\AlbumTable’ => function($sm) { 
                $tableGateway = $sm->get(’AlbumTableGateway’); 
                $table = new AlbumTable($tableGateway);
                return $table;
            },
            ’AlbumTableGateway’ => function ($sm) {
                $dbAdapter = $sm->get(’Zend\Db\Adapter\Adapter’);
                $resultSetPrototype = new ResultSet(); $resultSetPrototype->setArrayObjectPrototype(new Album());
                return new TableGateway(’album’, $dbAdapter, null, $resultSetPrototype);
            }, 
        ),
    ); 
}
}

And here is my module.config.php code in /module/Album/config/:

return array(
’controllers’ => array(
    ’invokables’ => array(
        ’Album\Controller\Album’ => ’Album\Controller\AlbumController’,
    ),
),

’view_manager’ => array( 
    ’template_path_stack’ => array(
        ’album’ => __DIR__ . ’/../view’,
    ),
),

'router' => array(
    'routes' => array(
        'album' => array(
            'type' => 'segment',
            'options' => array(
                'route' => '/album[/][:action][/:id]',
                'constraints' => array(
                    'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'id' => '[0-9]+',
                ),
                'defaults' => array(
                    'controller' => 'Album\Controller\Album',
                    'action' => 'index',
                ),
            ),
        ),
    ),
),'
);

I have read through a few people who have ran in to similar situations, but their issues were due to misspelled/incorrectly named classes. I don't see anything wrong with my code (even went as far as copying/pasting directly from tutorial).

Can someone give me some suggestions?

Thanks

like image 738
Matt Altepeter Avatar asked Jan 27 '26 17:01

Matt Altepeter


1 Answers

I had the same problem, and the solution was to start every .php file with <?php This is not clear in the tutorial (if you just copy the code from there), and it was the reason I was getting the same exception.

like image 120
nullbuilt Avatar answered Jan 30 '26 05:01

nullbuilt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!