Reputation: 3033
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.
Upvotes: 1
Views: 1770
Reputation: 2544
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...
Upvotes: 2
Reputation: 12675
There is a very good documentation online. Just work through it and you'll understand whats going on. I also teached myself ZF2 not long ago and here are some helpful links:
First do the quickstart: http://framework.zend.com/manual/2.3/en/modules/zend.mvc.quick-start.html
Other important links:
http://framework.zend.com/manual/2.3/en/user-guide/modules.html#configuration http://framework.zend.com/manual/2.3/en/modules/zend.service-manager.quick-start.html http://framework.zend.com/manual/2.3/en/modules/zend.module-manager.module-manager.html http://framework.zend.com/manual/2.3/en/modules/zend.mvc.routing.html
Upvotes: 2