1. Fabrik 3.8.1 has been released. It is mostly bug fixes and feature enhancements, but does include two new plugins (push notifications, and the sequence element). As usual we strongly recommend testing the new release on a sandbox if your application is mission critical, and always do an Akeeba backup before updating.

Debugging

Jan 27, 2018
Debugging
  • There are several ways you can debug your php code depending on the issues you are having. Most of the methods below will display a string, so you also need to know how to convert arrays and objects to strings in order to display them.


    Converting other types of data to strings(top)


    Converting an array to a string(top)

    PHP:
    $string = json_encode($array);

    Converting an object to a string(top)

    Assumiong that your object implements a __toString() function:
    PHP:
    $string = (string) $object;

    PHP echo(top)

    The most obvious way to output debugging information is to use the php "echo" statement. However, this is not always as straightforward as you might think because the output will often appear somewhere in your HTML which may not be immediately obvious or even visible, but can sometimes be missing altogether if you outputted it during a php output buffer capture ("ob_start"):
    PHP:
    echo "$string = " .  $string;
    You may need to use your browser's Developer's Tools to search for the output.

    You also need to be aware that if page headers are still being created, your output will terminate these and may create other output oddities.

    Joomla's standard message area(top)

    Possibly the easiest way to put a debug message on screen is to send it to Joomla's standard message area:
    PHP:
    JFactory::getApplication()->enqueueMessage($string, 'message');

    Fabrik's debugging infrastructure(top)

    If you want to leave debugging code permanently in your php, then you can use Fabrik's own debugging system.

    Turning on Fabrik's debugging system(top)

    To view additional debug output showing what Fabrik is doing, you need to do two things:
    1. Set 'allow fabrik debug' to either 'Yes' or 'Debug JS' in Fabrik's global parameters.
    2. Add to the end of the URL the following string:
      Code (Text):
      &fabrikdebug=1
      or
      Code (Text):
      ?fabrikdebug=1
      if there are no query parameters in the URL already.

    Permanent debugging statements(top)

    To display your own debugging information alongside Fabrik's, use:
    PHP:
    FabrikHelperHTML::debug($string, 'debug:heading');

    Browser Developer's Tools(top)

    To get debugging information when the output is being sent in response to an Ajax call for e.g. field or form validation or for calc elements, and is not immediately visible the browser window.

    You can use the following methods :

    Use your browser's Developer's Tools(top)

    To display variables, you can use the PHP var_dump() function :
    PHP:
    var_dump("MY_VAR : ",$my_var);
    exit;
    When the , this will stop the execution of the plugin and you will get the following error on your form :
    SyntaxError: JSON.parse: unexpected character

    For example in Firefox's Developer's Tools / Firebug, in the Javascript Console you will see a POST with:
    Click on the '+' symbol before "POST". You will see a new menu, by default on "Response" tab. Click on "HTML" tab, you will see your dump in a more visible way.

    If you want to display many variables, you can write :
    PHP:
    echo "found : " . $found . "\n";
    echo "status : " . $status; exit;
    The "\n" is to display the next variable on a new line.
    And don't forget to write "exit;" on the last line !

    http://screencast.com/t/1lPY94LRQdsD

    Joomla JDump extension(top)

    JDump allows you to display your debugging output in a popup window, without stopping the execution of your code. Just insert in your code something like:
    PHP:
    dump($variable, 'Variable Name');

    See also...(top)

    https://docs.joomla.org/How_to_debug_your_code
    https://www.joomlabeginner.com/blog/tutorials/59-how-to-use-joomla-debug-system