Model-View-Controller pattern in a web application

Terence Par described MVC in web applications as follows:

  1. M represents an application’s data (including the persistence layer such as a database), all of the business logic, and any model-related computations.
  2. V represents a page's template or templates
  3. C represents both the server’s dispatch infrastructure that maps a URL to a code snippet and the code snippet itself
The controller should be as lightweight as possible, and acts like an event manager, dictating when a page's code gets executed. The controller in this respect has two parts:
  1. the 'overlord' that maps incoming HTTP URL requests to a particular handler for that request
  2. the handlers themselves, which are often called "controllers." The controller also receives requests (including HTTP POSTs etc) and processes these, probably using the Model to do this. The controller then pushes the response into the views or templates.

Running PHPUnit tests from Eclipse Helio

This article describes how to unit tests from the Eclipse - Helio IDE, using PHPUnit as an external tool.

Installing PHPUnit for PHP 5.3 on ZendServer

ZendServer installs PHP CLI as part of the installation, and, as is customary for PHP 4.3+, includes a PEAR installer. It's a good idea to install PEAR before installing PHPUnit as per the recommendation here.

Central User Authentication using Zend Framework

User authentication is about checking if the user is authentic i.e. the user has a valid identity. Authentication is most commonly done using username (or email) and a password.

When, and how, do you check if the user is authenticated? One way is to use a plugin to provide centralised authentication. The plugin can decide if the user should login based on the requested url. As an example, you might have an 'admin' module where you want the user to be logged in before he/she can access the module. Rather than having code to check for this in every controller or action, just add it to a plugin which is automatically called during application boot up.

Content Compression Using PHP

Content compression is probably the easiest approach to reduce page weight, and can have a big impact on page load times. Not all content can be compressed - images, PDFs etc are likely to be compressed already. The best candidates are text files - HTML, XML, CSS, Javascript etc

HTTP 1.0 introduced the idea of content encodings. The Accept-Encoding request-header was expanded on in HTTP 1.1, enabling a browser/client to notify the server that it can accept compressed content by sending the header. The Accept-Encoding header can be set as follows: Accept-Encoding: gzip,deflate or with just one of gzip or deflate. PHP will automatically choose the correct compression to use. Gzip is by far the most popular and widely used compression method. For Apache 2.x, gzip compression is handled by the mod_deflate module.

Tags: 

Pages