NetBeans IDE supports Software as a Service (SaaS) applications in PHP. SaaS refers to a software application delivery model where a software vendor develops a web-native software application and hosts and operates the application for use by its customers over the Internet. SaaS is an increasingly popular model for providing software functionality as it is economical in terms of both cost and customer hardware resources. By using SaaS PHP support in Netbeans IDE, PHP developers can consume popular web services such as Google Maps just by dragging-and-dropping these services from the IDE's Services window into PHP files.
This tutorial uses the Google Map service to demonstrate SaaS PHP support.
In order to use SaaS services in PHP you must have the PHP Extension and Application Repository (PEAR) installed. After PEAR is installed, include the path to PEAR in the include_path variable in your php.ini file. Then install the following PEAR packages:
The procedure for installing and setting up PEAR varies according to the operating system you are using and the AMP package you have installed, if any. For example, to install PEAR in the Xampp package:
Run the Xampp go-pear script (location varies by OS) to install PEAR. This creates a PEAR directory (again, location varies by OS).
Open php.ini and add the path to the newly-created PEAR directory to the include_path variable for your operating system. Uncomment include_path if it is commented out. For example, using Xampp on MacOS, the include_path variable is:
Optionally, add the path to PEAR to your Path environment variable (on Windows).
Open a command prompt in the PEAR directory and run the command pear install Http_Request. This installs the Http_Request package and any packages on which Http_Request has dependencies, which include Net_URL and Net_Socket. If these packages are already installed, PEAR returns "Nothing to install."
Creating the PHP Project
After you set up PHP and PEAR, create the PHP project that will use the Google Map Service.
To create the project:
Choose File > New Project. Under Categories, select PHP.
Under Projects, select PHP Application and click Next. The Name and Location page opens.
Name the project GoogleMapApp. Save it in your default project folder, which is the web folder of your Apache server. Click Finish.
The IDE creates the project as a Local Web Project, run on your local Apache server at http://localhost/GoogleMapApp/. The project's index.php file opens in the editor.
Adding and Running the Google Map Service
You add SaaS operations to PHP files by dragging the operation from the Web Service Manager in the Services window and dropping it into the body of your PHP file.
To add the Google Map Service to your PHP project:
In the IDE, open the Services window.
In the Services window, expand the Web Services node and navigate to Google > Map Service > getGoogleMap.
In the editor, remove the existing <?php...?> tags from index.php. Drag the getGoogleMap operation from the Services window and drop it into the <body> element of index.php. A dialog opens for setting initial values of input parameters.
Leave all input parameters at default values and click OK. The IDE inserts the PHP for calling the Google Map service into the body of index.php, with the parameters you chose.
In the Projects window, expand the
org_netbeans_saas_google package and open googlemapservice.properties. Paste in the API key you got from Google
In the org_netbeans_saas_google package, open GoogleMapService.php. Find the line $cl = new RestConnection(GEOCODE_URL, $queryParams); and change it to $cl = new RestConnection(GEOCODE_URL, $queryParams, null);. If you do not do this, you get a "Missing Argument 3 for RestConnection()" error when you run the project, even though the map displays correctly and the third parameter should just be null.
Start your PHP engine.
In the Projects window, right-click the project node and select Run (Shift-F6) from the context menu. A browser window opens, displaying the Google map of the address specified in index.php.