Mobile Server-side Development

From HTML5 Builder
Jump to: navigation, search

The server-side part of a mobile application is the part responsible for the generation of the pages of the application when deploying it as a stand-alone application to be shipped to mobile devices.

Using AJAX, you will be able to write logic for your mobile application server-side, so it will be processed in a web server called from the stand-alone version of your application, running on a mobile device connected to the internet. Yet, you should write the logic of your mobile application using client-side code whenever you can, so it works even when the mobile devices lack of a working internet connection.

MPage Subclass

Each page of a mobile application is defined in a file of its own, a form. In that form, you load the RPCL, as well as the units of the RPCL library you are going to use, and then you define a subclass of the MPage container. That subclass is the one defining your mobile page.

When you create a new form, this is what you get:

<?php

  // Load the RPCL.
  require_once("rpcl/rpcl.inc.php");

  // Load the units of the RPCL to be used.
  // These are some basic units for mobile applications.
  use_unit("jquerymobile/forms.inc.php");
  use_unit("extctrls.inc.php");
  use_unit("stdctrls.inc.php");

  // Define a subclass of MPage.
  class MPage1 extends MPage
  {
  }

  // Get the global variable $application, common to all the forms in your project.
  global $application;

  // Define a variable to hold your MPage subclass as global.
  global $MPage1;

  // Assign an instance of your subclass to that variable.
  $MPage1 = new MPage1($application);

  // Load the data on the resource file.
  // Resource files (.xml.php) contain the data defined through the Object Inspector.
  $MPage1->loadResource(__FILE__);

  // Output your page.
  // This method prints the HTML page structure, goes through all the components
  // you defined for your MPage subclass, and outputs their content.
  $MPage1->show();

?>

Components

Once the MPage subclass is defined, you can start adding components to your form. The server-side logic of your pages will be determined by the components they include, and the values the properties of those components have. If you are using AJAX, you can also define events handlers to run PHP code in response to PHP events, as well as PHP methods to be called client-side.

Help Resources

Documentation