Question

I am new in zend 2. I have difficulty in understanding of module.config.php file.

such as what is service_manager,translator,view_manager,console,router,routes etc.?
where, when and how to use this configuration?

I search zend2 documentation, but didn't found details. I also found diff. tutorials but they are not explain the code.

Thanks in advance.

Was it helpful?

Solution

Module.config.php it's a file wich contains all specific configuration for your module, this file will be merged with other config params in other module. You have to understand that ZF2 is module driven, it means that each module works independantly from the others, and each module can works with other module but still, if you deactivate one module your application still work.

But each module needs specific configuration and that's why you module.config.php is for.

Service manager Allow you to instanciate factories like this :

    'controllers' => array(
        'factories' => array(
            'Test\Controller\Test' => 'Test\Factory\TestControllerFactory',
        ),
    ),
    'service_manager' => array(
        'factories' => array(
            'Test\Service\Test' => 'Test\Factory\TestServiceFactory',
        ),
    ),

When you have a model like this :

Entity<-DAO<-Service<-Controller<-View

You instanciate your factories via Service manager, this is used for dependancy Injection. My TestService for example depends on other class (like ObjectManager) Or my controller needs to be instanciate with TestService dependancy. Service Manager can inject an instance in other object.

If you have to learn zf2 you can begin by Album tutorial on the official website.

translator

Translator in module.config.php can allow you to define the default local of your module and define also where your translation are stored.

View manager is made for tell to the application where your views are. You have to declare a template_map (it's faster than template path stack) But it's nice to declare both. you have just to put in there where your views file are.

routes

Your routes for your module and only for the module (each module are independant), config will be merged, remember that.

If you want a example you can check this repo on github : Album tutorial

Edit2 : For understand well, Zend Framework maybe you have to check first design pattern &concept used : Factory DAO Dependency Injection and others...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top