Zend Framework: controller class == Page?

I understand correctly that in the Zend Framework, if I plan to have 5 pages on my site, do I usually need 5 controllers? Do ZF developers usually create 1 controller per page ("page" as an abstraction of an application unit)?

The reason I ask about this is because earlier, for some reason, I imposed many different actions on the controllers so that they play the role of pages, for example. index / add, index / view, index / delete and display various small screens, for example. small CRUD screens, unlike grids displayed by index action.

But now I want to check my new understanding that actions are mainly needed to update the model, and actions should immediately be redirected back to the controller / index after starting. Thus, it seems that views should be mainly used in index actions, and less often in other actions.

Is this sound architecturally sound?

+4
source share
3 answers

I guess this is one way to do this ... Using your analogy, I suggest that I use the controller as a β€œsection” and actions like β€œpages” for these sections.

But this is more focused on the old procedural static page paradigm, because indeed the action controller itself is no longer associated with the page or section than the association that you create as a developer. I.e. each page could potentially be part of numerous actions and views related to the application architecture.

For example, if I have blog modules, I might have the following:

Controllers

  • Postcontroller
  • CommentController

Views:

  • post
    • display (display of one record)
    • (list of messages)
    • edit (create / edit message)
  • comment
    • display (display n comments)
    • list (list comments)
    • edit (create / edit / moderate comment)
    • embed-list (for use on the Post itself, if this is different from the display)
+3
source

In my opinion, the controller should always group several methods that share a common use case. Try to find "nouns" that describe the functionality of your application: these are controllers (while verbs are controller methods).

If you have (for example) a blog, you can:

  • ArticleListController (a list of all articles listing the top 10, listing all articles for a tag, ...)
  • SingleArticleController (displaying one article, adding comments, ...)
  • AdminController (allows you to write articles)

If you have only 5 pages (e.g. home, about, contact, ...), the MVC architecture may not be suitable.

+2
source

indexAction is simply the default action for this controller, useful for displaying the default view (the same as displaying the index.html or index.php page for a subdirectory).

It is completely permissible to create various actions on the basis of each controller, which may or may not have their own representations (i.e. add and edit). The controller is designed to group such actions.

For example, see the Zend_Controller_Action documentation. You might also find it useful to familiarize yourself with the Zend_Controller workflow.

+1
source

All Articles