25.09.2014 Views

ZEND PHP 5 Certification STUDY GUIDE

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Elements of Object-oriented Design ” 175<br />

if (array_key_exists($name, self::$_register)) {<br />

return self::$_register[$name];<br />

} else {<br />

$msg = "’$name’ is not registered.";<br />

throw new Exception($msg);<br />

}<br />

}<br />

public static function exists($name)<br />

{<br />

$name = strtolower($name);<br />

if (array_key_exists($name, self::$_register)) {<br />

return true;<br />

} else {<br />

return false;<br />

}<br />

}<br />

}<br />

$db = new DB();<br />

Registry::add($db);<br />

// Later on<br />

if (Registry::exists(’DB’)) {<br />

$db = Registry::get(’DB’);<br />

} else {<br />

die(’We lost our Database connection somewhere. Bear with us.’);<br />

}<br />

The Model-View-Controller Pattern<br />

Unlike the patterns we have seen this far, Model-View-Controller (MVC) is actually<br />

quite complex. Its goal is that of providing a methodology for separating the business<br />

logic (model) from the display logic (view) and the decisional controls (controller).<br />

In a typical MVC setup, the user initiates an action (even a default one) by calling<br />

the Controller. This, in turn, interfaces with the Model, causing it to perform some<br />

sort of action and, therefore, changing its state. Finally, the View is called, thus causing<br />

the user interface to be refreshed to reflect the changes in the Model and the<br />

action requested of the Controller, and the cycle begins anew.<br />

Licensed to 482634 - Amber Barrow (itsadmin@deakin.edu.au)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!