PHP Registry - Accessing objects in other objects.

Discussion in 'PHP' started by subdivisions, Oct 19, 2011.

  1. #1
    Probably a dumb question but I'm trying to break free from CakePHP's bottlefeeding.

    I'm writing a basic framework for myself and I've got the registry concept down, but I can't figure out how to use objects in other objects. For example, I can load "database" and "template" just fine, and they function perfectly on their own, but I can't use database from inside template... Do I need to load the registry in every object? Seems to defeat the purpose if so.

    Thanks for your help.
     
    subdivisions, Oct 19, 2011 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    There are 2 options, make the object global! or pass it to other objects

    for example
    $GLOBALS['db'] = new database(); // globaly setting it up

    or use it by passing it to other objects
    $tpl = new template(Database $db)

    Hope you get my point.
     
    EricBruggema, Oct 21, 2011 IP