How to Build Mobile and Native Apps with RadPHP XE2 and Update 3
RadPHP XE2 is a powerful tool for creating web and mobile applications using PHP and HTML5. With Update 3, you can also create native Android apps that run on devices without a web browser. In this article, we will show you how to use RadPHP XE2 and Update 3 to create a simple app that displays a list of products from a database.
Step 1: Install RadPHP XE2 and Update 3
To use RadPHP XE2 and Update 3, you need to have a valid license for RadPHP XE2. You can download the trial version from here. After installing RadPHP XE2, you need to download and install Update 3 from here. Update 3 includes the Android SDK and NDK, which are required for creating native Android apps.
Step 2: Create a New Project
Launch RadPHP XE2 and select File > New > Other > RadPHP Projects > Mobile Application. Give your project a name and click OK. You will see a blank mobile form in the designer. You can drag and drop components from the Tool Palette to the form, or use the Object Inspector to change their properties.
Step 3: Add Components to the Form
For this example, we will use a DBGrid component to display the products from a database, and a Button component to switch between web and native modes. To add a DBGrid component, select Data Controls > DBGrid from the Tool Palette and drop it on the form. To add a Button component, select Standard > Button from the Tool Palette and drop it below the DBGrid. Change the Caption property of the Button to \"Switch Mode\".
Step 4: Connect to a Database
To connect to a database, you need to use a DBConnection component and a DataSet component. For this example, we will use an SQLite database that contains a table called Products with three fields: ID, Name, and Price. To add a DBConnection component, select Data Access > DBConnection from the Tool Palette and drop it on the form. Double-click on the DBConnection component to open the Connection Editor. Select SQLite as the Driver Name and browse for the database file. Click Test Connection to verify that the connection is successful. Click OK to close the Connection Editor.
To add a DataSet component, select Data Access > DataSet from the Tool Palette and drop it on the form. Double-click on the DataSet component to open the DataSet Editor. Select SQL as the DataSet Type and enter \"SELECT * FROM Products\" as the SQL Statement. Click Execute to populate the DataSet with data from the database. Click OK to close the DataSet Editor.
To bind the DBGrid component to the DataSet component, select the DBGrid component and change its DataSource property to DataSet1 (or whatever name you gave to your DataSet component). You should see the data from the database displayed in the DBGrid.
Step 5: Add Code to Switch Modes
This code checks if the app is running in native mode or web mode using PhoneGap()->isNativeApp() method. If it is running in native mode, it switches to web mode using PhoneGap()->switchToBrowserMode() method. If it is running in web mode, it switches to native mode using PhoneGap()->switchToNativeMode() method.