0

I'm trying to setup a ZF2 project (slightly different from the zf2skeleton) and I want to use composer to deal with all the autoloading, not only from the vendor ones (installed through composer) but also those modules I create.

For some reason, i can't get access to my Application module Index controller. I think its the autoloading that's not working... I just don't know what i might be doing wrong..

Thanks!

Files and data below:

This is my folder structure:

index.php
private
- modules
-- Aplication
--- src
----- Aplication
------- Controller
---------- IndexController.php
- vendor
-- zendframework
-- composer
-- autoload.php
- composer.json
- composer.phar

main.config.php

return array(
    'modules' => array(
        'Application',
    ),
    'module_listener_options' => array(
        'config_glob_paths' => array(
            'private/config/autoload/{,*.}{global,local}.php',
        ),
        'cache_dir' => realpath(dirname(__DIR__) . '/../../data/cache'),
        'module_paths' => array(
            realpath(__DIR__ . '/../module'),
            realpath(__DIR__ . '/../vendor'),
        ),
    ),
);

index.php

include_once 'private/vendor/autoload.php';

$application = Zend\Mvc\Application::init(include 'private/config/main.config.php');
return $application;

composer.json

{
    "repositories": [
        {
            "type": "composer",
            "url": "http://packages.zendframework.com/"
        }
    ],
    "require": {
        "php": ">=5.3.3",
        "zendframework/zendframework": "2.*"
    },
    "autoload": {
        "psr-0": {
            "Application\\": "module/Application/src"
        }
    }
}

Application config

return array(
    'router' => array(
        'routes' => array(
            'home' => array(
                'type' => 'Zend\Mvc\Router\Http\Literal',
                'options' => array(
                    'route' => '/',
                    'defaults' => array(
                        'controller' => 'Application\Controller\Index',
                        'action' => 'index',
                    ),
                ),
            ),
        ),
    ),
    'controllers' => array(
        'invokables' => array(
            'Application\Controller\Index' => 'Application\Controller\IndexController'
        ),
    ),
);

IndexController

namespace Application\Controller;

use Zend\Mvc\Controller\AbstractActionController;

class IndexController extends AbstractActionController {

    public function indexAction() {
        die("app ok");
    }

}
MGP
  • 653
  • 1
  • 14
  • 33

1 Answers1

1

First, from what I see, you don't run your application :

$application = Zend\Mvc\Application::init(include 'private/config/main.config.php');
$application->run();

Another point is that, you don't have to use composer to load your modules. As your application config already include the module directory, the Module loading process will automatically scan the directory and use the loading strategy defined at the level your Module classes.

yechabbi
  • 1,881
  • 17
  • 14
  • That was in fact the problem. But, why not use composer? What if i wanted to keep an "update method" but dont want to dump everything in the vendor folder? :| (that was my idea..) – MGP Jan 29 '13 at 16:56
  • 1
    your vendor folder is also marked as a module directory, See module_paths key on your config array – yechabbi Jan 29 '13 at 16:59