Using Delphi for PHP

AJAX Applications

Set the following settings:

  • Enable form to process AJAX. Eg: Form1.UseAjax = true;
  • Enable control to call AJAX routine. Eg: For Button1 control create a routine like this:
    class Form1 extends Page {
       $Button1 = null;
       . . .  // other controls defined here
     
       function Button1JSClick($sender, $params)
       {
          echo $this->Button1->ajaxCall("WhateverRoutineToCall");
          ?>
            // always finish with this javascript statement
            // when using a Submit button (if you do not want
            // to reload the form.    
            return(false);  
          <?php
       }
     
       function WhateverRoutineToCall()
       {
          // do something here (just do not include echo statements)
       }
     
       . . .  // other functions defined here
    }
     

Note: Do not put echo statements in the function that is called by ajaxCall(). Otherwise the AJAX code will not work.

Localize an Application

Perform the following steps:

  • Any references to a string in your code (eg: echo “Hello, world!”; ) should be replaced by a call to gettext() or _(). Eg:
    echo _("Hello, World!"); 
  • Set the Language property for the form to the required locale.
  • Translate the user interface in the form to the required locale. This creates a form1.<locale>.xml.php file that contains all the specific changes made to that locale.
  • Run the Internationalization Wizard (Tools > Internationalization Wizard) to create the directory structure and files used by gettext.
  • Create or edit the localization files for your language using poEdit. poEdit calls it a 'catalog'. The file is found in the project directory under locale/<locale>/LC_MESSAGES/messages.po. After saving the poEdit catalog (eg: messages.po file), poEdit will create a .mo binary file which is what it is used by your application.
  • Set Language property in the OnCreate event for the form, and translate the required form controls. Eg:
    function Form1Create($sender, $params)
    {
      // set locale
      $this->Language = "Danish";
     
      // translate form controls
      $this->btnSave->Caption        = _("Save");
      $this->btnDownload->Caption    = _("Download");
      $this->lblLanguage->Caption    = _("Language");
      $this->lblProductName->Caption = _("Product Name");
      $this->lblCompanyName->Caption = _("Company Name");
     
    }

Documentation and Support