Zend framework 2

I am a big enthusiast about the new Zend Framework. So far I have been doing one project in the previous version, and I decided to study a new one that contains really hard parts to understand for me.

I watched youtube webinars and videos, I also read the documentation, and I try to understand this structure by simply reading the code, but there are a few things that I just canโ€™t understand.

The EventManager have a lot of information about EventManager , but since I am lacking in English, I just cannot understand 100% of the speech.

I know that the event manager manages events that are completely obvious, but I really donโ€™t know how to use it: at one of the webinars they provide simple examples, but they donโ€™t explain where to place this code, module.php file? Or some other place, if you can show me some practical example with an explanation so that I can understand what is the point.

It follows that the mysterious $e passed as an argument to most functions from module.php , which is then used as follows: $e->getApplication or something that I'm just curious about, what does this $e mean? This is an example of what? And the next thing: how is it automatically passed to these functions?

Another problem: the configuration files that are listed for each module called module.config.php have a lot to do. I understood what routes I understood, but I canโ€™t understand what invokables and factories are. This is also explained in one of the webinars as follows: invokables are class paths, factories are function calls or classes (don't remember). The point is fine, it makes sense in some theoretical conversations, but please provide me some examples with a detailed explanation of where these factories and invokables, and other things that I need to know, occur.

Another thing is that there are many configuration options in these configuration files. Where can I find information that "keys"=>"values" possible in these files?

That's all for now, but there are still unanswered questions that I would like to ask. If someone can help me, I would really like him to correspond by mail with this person.


Ok, one problem is resolved. One about the mysterious & e, so if somene is intersted here, this is the solution:

This instance of the $ e variable depends on what function we use in the module.php file:

case 1: init () โ†’ & e is an instance of the module manager case 2: onBootstrap () โ†’ & e is an instance of MvcEvent (if there are other cases that I found, please let us know)

The fact is that these methods are called when the event is triggered, so the mysterious & e is passed to these functions by listeners who listen if these functions are displayed in our code (this is my simple logic, so please do not hate me)

There are other questions that need to be answered. As soon as you find some robust answer, I will let you know

+4
source share
2 answers

Inside ZF2 code, $e always an instance of Zend\EventManager\EventManagerInterface . Usually this is either Zend\EventManager\Event , or Zend\Mvc\MvcEvent .

The EventManager class fires an event that raises listener calls. Each listener callback is passed an instance of Event , which then has some useful methods, especially getTarget() and getParams() . Other instances of EventManagerInterface usually have more specialized methods. MvcEvent , in particular, has methods related to the Mvc component, such as getApplication() , getRouter() , getRequest() and getResponse() .

+3
source

You can find more detailed information on tghe EventManager, application configuration and MvcEvent in the book "Using Zend Framework 2": http://leanpub.com/using-zend-framework-2

0
source

Source: https://habr.com/ru/post/1432928/


All Articles