Mvc design question

I use the Zend framework and doctrine in this application

In my web application, I have various separate modules, such as events, conferences, case studies .. that's why I am doing the controller design at the moment. In the document below, the regulatory document is the controller, and its subsystem is its actions. Thus, regulatory documents, videos, podcasts have almost the same functionality. so this design fits ...? In mvc for each action I will have a separate view. And as a user, I may need to set access levels on these modules. so I kept a separate controller so that I could easily control the module for each type of user. But this leads to code duplication.

enter image description here

Now I am thinking of making one parent class and in this case I will have all the common methods. eg. I will have the shared resources of the class and I will store the list, search, suggestion, addFavorite, etc. And this will be the parent for the above controllers.

So how can I control my presentation for all of these different modules if I go with this approach ...? if I go with this, than my code will be a bit messy ..?

+8
php design-patterns model-view-controller zend-framework
source share
4 answers

If I understand you correctly, you have a set of general rules of conduct among your regulatory documents, videos, and podcasts.

In this case, you should probably try to divert the similarities to the parent class from which these three areas inherit.

As an example, I have my own MVC environment where I define the superclass tnh_controller from which my other controllers are inherited (for example: site_controller, group_controller). In the parent controller, I define the header () and footer () and delete () methods. Then I can use those that do not change in child classes, and save on that.

You can also do some general work for your models (CRUD) in the model superclass, only redefining it if necessary. Most of the logic for different models comes from class variables (table names, column names, etc.).

I would not worry too much about being "strict" MVC. Instead, try to figure out what will save your time and save your code. It looks like you're on the right track by putting similar behavior at the parent level.

0
source share

I would suggest that all controllers have good URLs and a clear structure in the modules, but keep the controllers thin. Put your domain logic in Services or Entities, so there is no (or simply less) code duplication.

More:

  • General MVC + service level in zend or PHP?
  • How to implement the service level in the Zend Framework?

From DDD:

Controllers

relate to the application layer / domain logic relate to the domain layer

+1
source share

The MVC design means that for each view you have a controller and a model. However, models do not have to be classes, and do not have a different model for each MVC. Usually you will share the model between some MVCs, or your model may just be an integer value that you define in your own controller. As a rule, you can even share data between them, then you will have singleton mode:

http://www.galloway.me.uk/tutorials/singleton-classes/

0
source share

You can have a separate controller that will contain add, addFavorite sentences without having to make it the parent class for all controllers. Basically, the UI elements associated with them, you can display as partial views and invoke actions in the corresponding controller. This way you can get rid of the problem with the views.

0
source share

All Articles