Chris
Chris

Reputation: 167

Using registry.php to store objects

My website at the moment runs like this,

index.php

config.php

loginObject

loginModel

Notice: Undefined variable: siteRegistry in F:\Projects\application\models\loginModel.php on line 37

This is line 37 -

$siteRegistry->storeObject("PDOExtender", "DBO");

I believe the problem is that it can't find the $siteRegistry variable from config.php, does anyone know how to fix this?

Upvotes: 0

Views: 303

Answers (1)

dog
dog

Reputation: 410

$siteRegistry = Registry::singleton();

As Registry (what ever it might be) is a singleton there is no need to use this $siteRegistry variable as a global. In fact you should always call Registry::singleton inside each function you want to use it. If that is to long just create a small wrapper function:

function reg() {
    return Registry::singleton();
}

The whole purpose of singleton objects is that there is always only one of them at a time, so you can always get them again during the programs execution without having to use variables.

Upvotes: 1

Related Questions