cornercorner
FeaturesPluginsDocs & SupportCommunityPartners

SaaSPHPTutorial

SaaS PHP Support Tutorial

Contents


1. Introduction

Using SaaS PHP support in Netbeans 6.5, PHP developers could consume most popular web services such as Google Maps, Yahoo News etc, just by drag-and-drop of these services from the Netbeans Services tab.

Note: NB6.5 M1 only support (for PHP) api-key based services such as Yahoo news, Google geocoder, Weatherbug, Zillow, Zvents. NB6.5 M2 will have support for Amazon S3, Delicious, Flickr, Facebook, StrikeIron, Twitter etc.

2. Setup

Note: Since I am using MacOSX, all of the illustrations will be targeted towards MacOSX. But you can use this documentation for any environment.

2.1 Installing PHP Engine

Click the link below to install PHP engine on your machine. Installing the Software and Configuring the Environment for PHP Development

2.2 Install PEAR (PHP web service packages)

If you installed PHP5, you should have at least a minimum set of packages from PEAR installed in /Applications/xampp/xamppfiles/lib/php/pear. In most cases you need to add this path to the php.ini file.

  • Open file /Applications/xampp/etc/php.ini
  • Edit following line append "/Applications/xampp/xamppfiles/lib/php/pear" to "include_path" variable (as shown below)
          • Added by go-pear

include_path=".:/Applications/xampp/xamppfiles/lib/php:/Applications/xampp/xamppfiles/lib/php/pear"

  • Check this by typing 'which pear'
dhcp-umpk16-82-196:main ayubkhan$ which pear
/Applications/xampp/xamppfiles/bin/pear

2.3 Install PEAR packages for Netbeans SaaS PHP support

  • Since NB SaaS PHP support depends on HTTP_Request package, you need to install Http_Request, Net_URL, Net_Socket packages. (See below)

Note: Since I have already installed these packages, I get "Nothing to install" message.

dhcp-umpk16-82-196:main ayubkhan$ pear install Http_Request
Ignoring installed package pear/Http_Request
Nothing to install
dhcp-umpk16-82-196:main ayubkhan$ pear install Net_URL
Ignoring installed package pear/Net_URL
Nothing to install
dhcp-umpk16-82-196:main ayubkhan$ pear install Net_Socket
Ignoring installed package pear/Net_Socket
Nothing to install
  • Check if the package(s) exist
dhcp-umpk16-82-196:main ayubkhan$ ls /Applications/xampp/xamppfiles/lib/php/pearArchive
HTTP		PEAR		System.php	pearcmd.php
Console		Net		PEAR.php	data		peclcmd.php
HTML		OS		Structures	doc		test

2.4 Install NB 6.5 from http://www.netbeans.org

3. Consuming SaaS services in PHP

3.1 Create PHP Project in Netbeans


Image:php_project_SaaSPHPTutorial.png


Image:project_config_SaaSPHPTutorial.png


Image:run_config_SaaSPHPTutorial.png

3.2 Check htdocs directory if "news" got created.


Image:htdocs_SaaSPHPTutorial.png

3.3 Drag and drop Yahoo news web service from Web Service nodes in Netbeans 6.5 "Services" tab. While doing provide parameter values if necessary.


Image:enter_params_SaaSPHPTutorial.png

3.4 SaaS support generates PHP code for consuming Yahoo news service.


Image:dnd_SaaSPHPTutorial.png

3.5 Modify index.php file if necessary as follows

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>
        <?php
        // put your code here

        include_once "org_netbeans_saas_yahoo/YahooNewsSearchService.php";
        try {
            $query = "php";
            $type = "all";
            $results = 10;
            $start = 1;
            $sort = "rank";
            $language = "en";
            $output = "xml";
            $callback = null;

            $result = YahooNewsSearchService::search($query, $type, $results, $start, $sort, $language, $output, $callback);

            //Comment this line
            //echo $result->getResponseBody();

            //Add following lines to display news nicely.
            $xml = $result->getDataAsXml();
            echo "<h2>Yahoo news search results for PHP</h2>";
            foreach ($xml->Result as $item) {
                echo "<a href=\"".$item->Url."\" target=\"_blank\">".$item->Title."</a><br/>";
                echo $item->Summary."<br/><br/>";
            }
        } catch(Exception $e) {
            echo "Exception occured: ".$e;
        }


        ?>
    </body>
</html>


Image:customize_SaaSPHPTutorial.png

3.6 Configure api key if necessary (for Yahoo news any non-null value is fine, but for other services you need to signup on thier web site to get an api key)


Image:enter_appid_SaaSPHPTutorial.png

3.7 Start Php engine (I am using Xampp. It provides single console to Start/Stop Apache/MySQL etc)


Image:xampp_SaaSPHPTutorial.png

3.8 Now run index.php to see the results.


Image:run_SaaSPHPTutorial.png

3.9 Yahoo news for java (since we provided 'java' as the value for the parameter 'query')


Image:yahoo_news_SaaSPHPTutorial.png