2

I have to use PHP code in contextual filter code in a "Arguments/Contextual Filters" of a view:

global $user;
$uid=$user->uid;

$pid=db_query("select pid from profile where uid='$uid';")->fetchField();

$equipo=db_query("select field_equipo_proyecto_target_id from field_data_field_equipo_proyecto where entity_id='$uid';")->fetchField();

$num_equipo=db_query("select field_num_equipo_proyecto_value from field_data_field_num_equipo_proyecto where entity_id='$equipo';")->fetchField();;

printf("%02d",intval($num_equipo));
return sprintf("%02d",intval($num_equipo));

I think I have some error because I can´t get a correct value. I would like to know how display variables such as $num_equipo, etc to debug my code easier.

0

2 Answers 2

2

To expand on what Adrian offered, I would add the Devel Debug Log module. I had a similar problem trying to debug code that ran from a rule, and, I found it easy to write the contents of variables to the log. I then went to Reports > Debug Messages and see what I needed to debug my code. The Debug Log module provides a ddl($message) function that is easy to use.

2

Install the Devel module with the Search Krumo module and you will be able to use the dpm() function.

Devel

  • Helper functions for Drupal developers and inquisitive admins.
  • Enable the included Kint submodule as for pretty print of variables. kint($array) function is provided, which pretty prints arrays. Useful during development. Similarly, a ddebug_backtrace() is offerred.

You can read how to use the Devel module at: Debugging Drupal (a page which gives a brief overview of some of the tools you can use to make Drupal development and debugging easier).

Not the answer you're looking for? Browse other questions tagged or ask your own question.