Jump to content

accessing object in arrays!!


mannyee

Recommended Posts

hi guys!!

after spending few months on oop based programming, i'm trying to structure my code in mvc way... and i found this tutorial at http://www.phpro.org/tutorials/Model-View-Controller-MVC.html by kevin waterson.  i can make almost all of it except the code on indexController.php

 

this class has a private variable $registry.  the author has assigned it an object that acts like a global variable. when i dump this variable as i get the following:

 

Registry Object (

        [vars:Registry:private] => Array ( [db] => PDO Object ( )

                                                          [router] => Router Object ( [registry:Router:private] => Registry Object *RECURSION*

                                                                                                  [path:Router:private] => C:\wamp\www\phpro\phprotest/controller

                                                                                                  [args:Router:private] => Array ( )

                                                                                                  [file] =>                                                      C:\wamp\www\phpro\phprotest/controller/indexController.php

                                                                                                  [controller] => index [action] => index )

                                                          [template] => Template Object ( [registry:Template:private] => Registry Object *RECURSION*

                                                                                                          [vars:Template:private] => Array ( [welcome] => Welcome to PHPRO MVC ) ) ) )

 

and later on the author uses the following code

 

/*** set a template variable ***/

        $this->registry->template->welcome = 'Welcome to PHPRO MVC';

 

to access a property $welcome in the template object.

 

....... as i understand template is just an array item in the vars[] array which is the private property of registry object (and this object is stored into the $this->registry property).... i don't understand the concept how the array item 'template' that stores the Template class object is used to access the Template class  property welcome to set the value.... i mean

 

if(is_object($this->registry->template))

  echo 'yes';

prints yes.

 

can someone shed the light on this?

Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.