Facts, Thoughts and Opinions

Forward vs. Redirect in Zend

Forward: The browser is unaware that a change of address has taken place. So, the URL remains the same. Note that if using PHP, the value of $_SERVER[REQUEST_URI] remains unchanged. If the ‘Reload’ button is hit after a forwarded request, the original request is sent (as url has not changed). Forwarding is always faster than a redirect.

Redirect: The application instructs the browser to go to a second URL (browser address bar displays the new url). If the reload button is hit, the second URL is fetched. Contents of the buffer are flushed before a redirect.

Typically, if a database change is done, use ‘redirect’. After you do a database update operation and display a confirmation page to a user, you do not want a refresh to mess with the database again. So, use a redirect to display the result of a processing.

List actions in a Zend hierarchy

ls /var/www/<directory>/application/modules/*/views/scripts/*/*.phtml | cut -d / -f 7,10-11 | cut -d . -f 1

MVC Pattern Overview

The MVC pattern separates the modeling of the application domain, the presentation, and the actions based on user input into three separate classes:

  • The model manages the behavior and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller).
  • The view manages the presentation of data to the user and transmits user input to the controller.
  • The controller interprets the user input transmitted to it, informing the model and/or the view to change as appropriate.

In a traditional client-side application, the pattern is quite straightforward. The user interacts directly with the view, and the view communicates with the controller. The controller processes requests from the view, makes requests of the model, and returns data from the model to the view. On the Web, however, the pattern is not quite as straightforward. The view outputs HTML, CSS and JavaScript to provide the interface that the user actually utilizes.

In recent years, web developers have learned that there are really two entirely separate MVC "stacks" in play: one on the server, one on the client. Modern JavaScript frameworks such as AngularJS and Backbone have emerged to support this paradigm to varying degrees.

The server-side stack uses an application framework such as Zend.

Server Client
Controller Model View Controller Model View
Zend controller Doctrine model Zend .phtml Backbone view controller Backbone collection HTML, CSS, JavaScript


  •   Subtopics

  •   Writings