I am learning how to use the template.php. And I have created a preprocess function. Within the preprocess function I have been putting my own data like strings in variables. Example:

function phptemplate_preprocess_comment(&$vars){
$vars['is_admin'] = FALSE;
$vars['happyday'] = 'Happy Gilmore';

and then in comment.tpl.php file I put

print $happyday
print $is_admin

Something to that effect.

All this data enters in correctly. I have even overwritten arrays with this. However I can not figure out how to effectively do this to an stdclass object array. It always says
recoverable fatal error: Object of class stdClass could not be converted to string.

My hunch is you can't do it this way it must be some kinda of a loading command or writing type command with a module.

I am just experimenting how to populate data into Drupal. This is a test site, so no worries I can mess with it.

Any thoughts how to get data into a stdClass Object array?

Thanks,

Comments

stevenc’s picture

The function "print" can only be used with scalar values - strings, numbers and booleans.

If you want to print an object or an array (for development/troubleshooting) use "print_r()"

Example:

print_r($myObject);

Otherwise, you can only print individual parts of an object or array:

print $myObject->title;
print $myObject->terms[0];

---------------------------------
Steven Wright

Slalom

luminusxp’s picture

Thanks for the reply. I appreciate it!