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
https://forums.phpfreaks.com/topic/212008-accessing-object-in-arrays/
Share on other sites

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.