Answer the question
In order to leave comments, you need to log in
What if it is necessary to have several models / controllers in one zf2 module?
Hello
This situation: you need a news module, each news should have a category - you can’t cram all this into one model, but these are not 2 different modules, that is, we need to cram several models and controllers into one module.
It would be stupid if this were not possible, and indeed, I seem to have seen a structure with several models in one of the modules, but I don’t really stick in how to do this and whether there will be pitfalls.
I understand correctly that in this case, I need to build something like this:
There will be a file with the Categories model, there will be a file with the News model. In the module config, we will connect 2 of these models. In terms of controllers, it will be about the same. CategoriesController and NewsController. In the first one, we will add, delete, change categories (we don’t need to view, we don’t need to view the list of controllers, by the way, in this case, what default route should I specify?). In the second case, it is a little more complicated: deletion, modification, preview (for the admin), as well as viewing all news and viewing the full news (for the user). All this will be connected to the admin panel, in which the paths that will call the necessary controllers and actions will be written.
Described how, in my humble opinion, everything should work. Here.
Questions:
Do I understand correctly how and what I need to do? I'm talking about structure in general.
If so, then:
1. What is the default path for the category controller? Stop though! After all, we specify the path for the module, and not for the controller. In this case, we don't have to mess around with the default paths for the categories, because the default path will be set for the entire module and it will be the path that will bring up the news list. Correctly?
2. Will it be correct to connect these modules in the admin panel in this way. I thought the paths would be like this (for the admin panel):
/admin/news/ (список новостей для администрирования)
/admin/news/edit/##
/admin/news/categories/ (список категорий для администрирования)
/admin/news/categories/add
Для пути news/edit/ вызовем контроллер новостей, edit action
Для пути news/categories/add вызовем контроллер категорий, add action
Answer the question
In order to leave comments, you need to log in
In my opinion, you did not understand how routes work in zf2, why write something extra, for example, a route is enough:
And what's wrong with several models in one module, read a few posts about them, one , two .
For the admin panel, it is better to immediately make a separate module.
All the same, all the logic should be in the services (and another example ) and it doesn’t matter where you call them from the news module or the admin panel.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question