User Rating: 1 / 5

Star ActiveStar InactiveStar InactiveStar InactiveStar Inactive

The registry is an object where site wide variables can be stored without the use of globals. By passing the registry object to the controllers that need them, we avoid pollution of the global namespace and render our variables safe. We need to be able to set registry variables and to get them. The php magic functions__set() and __get() are ideal for this purpose.

Open the registry.class.php in the applications directory and put the following code in it.

Class Registry {
private $vars = aaray();
public function__set($index, $value)
   $this->vars[$index] = $value;
public function__get($index)
return $this->vars[$index];

With the registry in place, our system is working. It does not do anything or display anything, but we have a functional system. The __set() and __get() magic function now allow us to set variables within the registry and store them there. Now to add the Model and router classes.