Feeds

Put some MVC in your PHP

Trial by separation

Build a business case: developing custom apps

Hands on The Model-View-Controller (MVC) architecture provides a useful three-tier pattern for building software, as MVC patterns decouple the graphical user interface (GUI) from the application logic.

That comes in useful when it comes to changing an application after it has been deployed. Separation of the views from the data means modifications made in the views do not affect the model and modifications made to the model to not effect the graphical user interface, simplifying maintenance. Also, an application may be expanded to add views and controllers that talk to a model without actually making any changes to the model itself.

Unfortunately for web developers, one of the features lacking in PHP until recently has been support for the MVC architecture. That has meant the MVC pattern has had to be implemented externally.

Some PHP frameworks have now added support for the MVC pattern, most notably the Zend Framework - one of the leading open-source PHP frameworks. Zend simplifies the task of developing secure, reliable web-based applications and web services. Zend provides an extensible code base, a flexible architecture and does not require any configuration files.

In this article we shall connect Zend to a database from Oracle, a company that's been working closely to optimize its software with Zend.

Fire up Zend

The Zend framework requires at least PHP 5.1.4. It's recommended to install PHP 5.2.2 or later because of the security and performance improvements in the newer version of PHP. Download the Zend Framework zip file from here and - if you don't already have it - download and install Apache 2.2.3, making sure it's configured with PHP. Then, add the following include_path directive to php.ini configuration file:

include_path=".;C:\ZendFramework\ZendFramework-1.0.1\library"

Enable the PHP database extension for Oracle database in php.ini.

extension=php_oci8.dll

Restart Apache HTTP Server. Install the Oracle database including the sample schemas and create a table Catalog using SQL script catalog.sql.

Create an MVC application

Now it's time to create a Create Read Update Delete (CRUD) application using Zend's MVC architecture that'll let us build, read, update, and delete an Oracle database table row.

In the MVC architecture the model represents the entities/class objects, the controller implements the business logic and integrates the model with the view, and the view represents the presentation layer or the user interface.

The MVC architecture in Zend Framework is implemented by the Zend_Controller component. The Zend_Controller_Front class provides a front controller for the MVC architecture. The front controller intercepts all requests and dispatches the requests to action controllers based on the request URL. The format of the request URL is http://localhost/controller/action. If no controller is specified the index controller and the index action are invoked. An action controller class extends the Zend_Controller_Action class. An action controller class is named with the notation <ControllerName>Controller. For example, the action controller class for the "index" controller is IndexController.

Secure remote control for conventional and virtual desktops

More from The Register

next story
'Stop dissing Google or quit': OK, I quit, says Code Club co-founder
And now a message from our sponsors: 'STFU or else'
Why has the web gone to hell? Market chaos and HUMAN NATURE
Tim Berners-Lee isn't happy, but we should be
Microsoft boots 1,500 dodgy apps from the Windows Store
DEVELOPERS! DEVELOPERS! DEVELOPERS! Naughty, misleading developers!
Apple promises to lift Curse of the Drained iPhone 5 Battery
Have you tried turning it off and...? Never mind, here's a replacement
Mozilla's 'Tiles' ads debut in new Firefox nightlies
You can try turning them off and on again
Linux turns 23 and Linus Torvalds celebrates as only he can
No, not with swearing, but by controlling the release cycle
Scratched PC-dispatch patch patched, hatched in batch rematch
Windows security update fixed after triggering blue screens (and screams) of death
This is how I set about making a fortune with my own startup
Would you leave your well-paid job to chase your dream?
prev story

Whitepapers

Top 10 endpoint backup mistakes
Avoid the ten endpoint backup mistakes to ensure that your critical corporate data is protected and end user productivity is improved.
Implementing global e-invoicing with guaranteed legal certainty
Explaining the role local tax compliance plays in successful supply chain management and e-business and how leading global brands are addressing this.
Backing up distributed data
Eliminating the redundant use of bandwidth and storage capacity and application consolidation in the modern data center.
The essential guide to IT transformation
ServiceNow discusses three IT transformations that can help CIOs automate IT services to transform IT and the enterprise
Next gen security for virtualised datacentres
Legacy security solutions are inefficient due to the architectural differences between physical and virtual environments.