Question

Right now, im using drupal for making a site. Im modifying the drupals user module, because i need to make a custom layout for the profile page.

Unfortenly im having issues for accessing trough the array.

all the data of the profile is on an array ($user_profile)

The array is just HUGE. im trying to navigate trough the objects.

While im doing a good job navigating (thanks to the print_r function), im facing a problem right now.

there's an object called entityInfo:protected. Inside this object there's more objects (by example, im trying to access to the object that is inside of this object, called label.

the issue is, if i try to do this:

echo $user_profile['profile_medico']['view']['profile2']['2']['field_tags']['#object']->{'entityInfo:protected'}->label 

I get the next message

Notice: Undefined property: Profile::$entityInfo:protected in include() (line 55 of D:\xampp\htdocs\specialdr\modules\user\user-profile.tpl.php). Notice: Trying to get property of non-object in include() (line 55 of D:\xampp\htdocs\specialdr\modules\user\user-profile.tpl.php).

I dont know how can i write this correctly so i can access to this object and keep going trough the arrays and objects... because i still have a loong way until i get to the objects i need to access.

By the way... if you want to see the array... http://fancomix.net/bigarray.txt

Thanks in advance.

Was it helpful?

Solution

It is simply ->entityInfo, :protected is not needed, it is an access modifier or visibility modifier. It is only displayed in the var_dump() to provide information about the property. An object property (and method also) can be declared either public, protected or private in PHP. You can read more about Visibility in the Manual.

protected means the property can only be accessed from an object method - no outside access, so you won't be able to get the property. The Profile class can have a getter method though - you should inspect the definition of that class to find it, or make necessary changes if you can, like changing it to public or writing a getter method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top