A simple, flexible, fast, and security-focused PHP framework
Nephtali documentation

Debugging in Nephtali

When things don't work the first time, Nephtali has some very basic debugging features built in that can help you figure out what went wrong.

Debugging display

The debugging display is only available when the mode for the site is set to "dev" in nconfig.php. Once this change is made, you can view the debug output for the last 10 requests handled by Nephtali by simply appending the get variable value "nmode=debug" to any request.

To illustrate debug mode, let's look at the Nephtali search results page. The screen shot below shows a search for "test" within the website.

Search results screenshot.

Nothing fancy there, but let's add the GET variable "nmode=debug" and refresh the page to view the debug display for that request.

Debug display screenshot.

As you can see, the page now shows debug output for the previous search request, including:

  • Ports and their corresponding values and validity.
  • Get, Post, Cookie, and Session contents.
  • And optionally, watched variables.

Watched variables

Nephtali provides another primitive debugging feature, watched variables, which are variables manually added to the debug display. Although the initial example didn't include any watched variables, let's add one so you can see the result.

For example, let's say that you wanted to watch the query value stored within the port. The PHP code below shows how you'd add a watched variable to the debug display:

PHP excerpt from nsite/search/index.php

   $name = 'search', 
   $function = function($markup)
      if ($rows = n\port\validate(array('q'))) {
         // q is invalid, so output safe value
         n\output\register('q', '[invalid]');
         // return feedback view
         return n\view\render($view = 'feedback', $markup, $rows);
      } else {
         // save q port for repeated use below
         $q = n\port\get('q');
         // include q value at this point in the debug output
         n\watch($name = 'q', $value = $q);
         // register search term as output value now that we now it's valid
         n\output\register('q', $q);
         // retrieve search results from google's search service
         if ($rows = nlib\google\search_site($site_url = 'nephtaliproject.com', $query = $q)) {
            return n\view\render($view = 'default', $markup, $rows, $opts = array(
               'whitelists' => array(
                  'titleNoFormatting' => array('<b>', '</b>', '&#39;', '&quot;'),
                  'content' => array('<b>', '</b>', '&#39;', '&quot;')
          } else {
             return n\view\render($view = 'empty', $markup);

With the above code in place, you would see the value for 'q' port, as shown in the screenshot below:

Watch variable screenshot.
blog comments powered by Disqus