Hi,

I try to develop my own module based on class PhpMyEdit.

I cannot render it into drupal theme :

the following php line :

return new phpMyEdit($opts);

generate this error :

recoverable fatal error: Object of class phpMyEdit could not be converted to string

Thanks for telling me how to render an object into drupal themes.

EddyL

Comments

j.somers’s picture

The error message is pretty straight forward. You are returning an object when you are trying to print a string.

Example:

$user= new stdClass();
print $user; // Error!

You will need to check whether the returned object, in your case of type phpMyEdit, contains something you want to print. For example, the standard $user object in Drupal contains, amongst other things, a "name" field so if you want to print that you need to do something like:

print $user->name; // Works, we are printing an individual field

So you will have to make the choice to return either a string, or use the object in your theme file and print the individual field there.

EDDYL’s picture

Thanks for that first answer Jansen.

Basicaly the 'normal' use of this class into a php page is to
include the phpmyedit class (require_once....) and then to display the object (new phpMyEdit($opts);)

That's all folk to make it work.

But in drupal it does not display the object.

Basically, this class return an object that consists in table rows from the mysql table you want to manipulate and buttons like 'Add' 'Edit' and so on...

I have no idea if it is possible to return fields as you descibed (return $object->field;) as the documentation do not explain the object in detail.

Is there a way to print an array of the fields from the object (outside drupal) to better understand how this object is built ?

Thanks,

Edouard

franciscohm’s picture

Hi Edouard,

Were you able to develop the module? Can you share it please?

I would like to test it since I would like to combine PHPmyEdit and Drupal. It would be a very cool combination.

Thanks very much

Best regards
Francisco