On-line documentation
  • PagePage
  • English
  • Arabic
  • French
  • German
  • Italian
  • Portuguese-br
  • Russian
  • Simplified chinese
  • Spanish
Writing PHP code
The following are some conventions to be adopted when writing PHP code in Docebo.

BUFFERED OUTPUT

To show HTML code in the page, the PHP print and echo functions should be avoided and instead you should use the ones offered by the PageWriter class. An instance of the PageWriter class is usually passed to the functions as a parameter called $out, but it can be obtained with the following code:

  $out=& $GLOBALS['page'];

The methods of the PageWriter class allow to store HTML code in a set of buffers, logically separated and addressed as "zones". It is possible to add HTML code at the beginning or at the end of each zone. The main functions are:

  function getWorkingZone()
    returns the zone currently used

  function setWorkingZone($zone)
    sets the current zone (it should be one of the allowed zones)
    
  function add($content, $zone = null)   
    adds text to the content present in the specified zone, or to the current zone if none is specified

The predefined zones are:

    'page_head'
      text placed in the HTML header (inside the HEAD tag)

    'blind_navigation'     
      text placed in the section devoted to hidden links, which are present to comply with the accessibility requirements

    'header'
      text placed in the page header (inside the BODY tag)

    'menu_over'
      text placed in the main horizontal menu

    'menu'
      text placed in the page menus

    'content'
      text placed inside the page contents

    'footer'
      text placed in the page footer

    'debug'
      text placed in the debug section of the page
 
For further information related to Docebo buffered output, give a look at:
  doceboCore/lib/lib.pagewriter.php

 

FORM USAGE

When writing forms, HTML tags should not be directly written. There is a class called Form that can ease the form management and guarantee that their code will comply with the XHTML standard. The Form class provides these main methods:

function openForm( $id , $action, $css_form = false, $method = false, $enctype = '', $other = '' )
opens the FORM tag with its attributes

function closeForm()
closes the FORM tag

function openElementSpace( $css_class = 'form_elem' )
opens the section for the form content

function closeElementSpace( )
closes the section for the form content

function openButtonSpace($css_div = false)
opens the button section

function closeButtonSpace( )
closes the button section

function getTextBox( $text , $css_line = 'form_line_text', $inline = false )
creates a textbox

function getLineBox( $span_text, $text , $css_line = 'form_line_l', $css_f_effect = 'label_effect' )
creates a texline

function getHidden( $id, $name, $value, $other_param = '' )
creates a HIDDEN field

function getTextfield( $label_name, $id, $name, $maxlenght, $value = '', $alt_name = '', $other_after = '', $other_before = '')
creates a text field

function getDatefield( $label_name, $id, $name, $value = '', $date_format = FALSE, $sel_time = FALSE, $alt_name = '', $other_after = '', $other_before = '' )
creates a date field

function getPassword( $label_name, $id, $name, $maxlenght, $alt_name = '', $other_after = '', $other_before = '' )
creates a PASSWORD field

function getFilefield( $label_name, $id, $name, $value = '', $alt_name = '', $other_after = '', $other_before = '' )
creates a file chooser field

function getDropdown( $label_name, $id, $name, $all_value , $selected = '', $other_after = '', $other_before = '' )
creates a dropdown menu

function getListbox( $label_name, $id, $name, $all_value, $selected = FALSE, $multiple = TRUE, $other_after = '', $other_before = '' )
creates a listbox

function getCheckbox( $label_name, $id, $name, $value, $is_checked = false, $other_param = '' )
creates a checkbox

function getRadio( $label_name, $id, $name, $value, $is_checked = false )
creates a radio button

function getRadioSet( $group_name, $id, $name, $all_value , $selected = '', $other_after = '', $other_before = '' )
creates a set of radio buttons

function getButton( $id, $name, $value, $css_button = 'button', $other_param = '' )
creates a button

For further information give a look at:
doceboCore/lib/lib.form.php

 

LANGUAGE KEYS USAGE

To allow easy translations of the application messages, textual strings should not be included in the code. Instead, language keys should be adopted. They are symbolic constants that refer to a message that can be present translated in many languages inside Docebo database.

Language management can be done through the administration interface and allows to insert new keys, to edit the existing ones and to add translations for those that are not already translated in a given language.

From the programmer's point of view, it is important to take into account that the names chosen for the new language keys should have a specific prefix, so that they will not overlap with other ones included in Docebo.

To show the content of a message you should use an instance of the DoceboLanguage class, that can be obtained with the following command: 
  $lang=& DoceboLanguage::createInstance($module, $platform, $lang_code);
where the meanings of the parameters are:
  $module = name of the module that contains the language keys (e.g. 'admin_content')
  $platform = platform in use (cms, lms, framework, ecc.)
  $lang_code = language to use (if not specified, the current language will be adopted)

Then, messaged can be extracted with the following code:
  $msg = $lang->def($key);
the $key parameter is the language key to show (e.g. '_BACK_TOLIST').

For further information related to the DoceboLanguage class, give a look at:
    doceboCore/lib/lib.lang.php