User Rating: 2 / 5

Star ActiveStar ActiveStar InactiveStar InactiveStar Inactive
 

The model is the "M" in MVC. The model is where business logic stored. Business logic is loosely defined as database connections or connections to data sources, and provides the data to the controller. Our database connection is a simple singleton design pattern and resides in the classes directory and can be called statically from the controller and set in the registry.

Add this code to the init.php file we created earlier\

<?php
$registry->db = db::getInstance();
?>

Like all registry members, the database is now globally available to our scripts. As the class is a singleton we always get the same instance back. Now that registry objects can be created a method of controlling what is loaded is needed