Mayank Kumar tech ramblings…

13Oct/091

MAX Lab Session Material: Creating Data Centric Applications using Flash Builder and PHP

Posted by

Flash Builder 4 Beta 2

Lab handout and sql script.

The version of WAMP which was installed on the lab machines can be downloaded from here.

Finally, in case you have any queries please post them at the Adobe Labs Forums.

Other References
Tour De Flex
Flex Devnet
Flash Builder 4 Tutorials
Flash Builder 4 Beta 2 and Flex 4 Beta 2 training videos

13Jun/090

Howto: Setup PDT & Flash Builder

Posted by

This setup allows you to edit and debug you PHP files along with your flex application in the same instance of eclipse. All features of PDT like PHP code coloring, auto complete will be available in addition to the wonderful features that Flash Builder 4 providesJ.

1. Download Eclipse 3.4.2 based PDT All-in-One bundle
a. Windows
b. Mac OSX Carbon

2. Extract it to a location of your choice. (say C:\opt\eclipse)

3. Download XDebug dll from http://xdebug.org/download.php. For the purposes of this tutorial I downloaded and used http://xdebug.org/files/php_xdebug-2.0.4-5.2.8.dll

4. Place this dll at any location accessible by your php installation, the PHP home directory itself is a good location.

5. Add the following entries to your php.ini file:

;
; Changes to enable XDebug
;

zend_extension_ts="C:/opt/php526/php_xdebug-2.0.4-5.2.8.dll"
zend_debugger.allow_hosts=127.0.0.1
zend_debugger.expose_remotely=always
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.profiler_enable=0
xdebug.profiler_output_dir="C:/temp"
xdebug.remote_enable=On
xdebug.remote_autostart=On
xdebug.remote_host=127.0.0.1
xdebug.remote_mode=req
xdebug.remote_log="C:/temp"

You need to be extra careful while editing the php.ini file as installations like WAMP tend to have a php.ini file inside the php folder and another one inside the apache/bin folder. The one under apache/bin is used. So a good way to figure out which php.ini file is being used by your PHP installation run phpinfo() and check the value of “Loaded Configuration File”

6. Restart your web server and view the phpinfo() output. XDebug should be listed there. If you don’t have a phpinfo() file, you can create one by putting the text below in a php file and saving it under your webroot. Then load the file in your browser.

<?php
 phpinfo();
?>

7. Now download the plug-in version of Flash Builder and install it. When prompted to select the host eclipse, choose the “Plug into another copy of Eclipse” option and enter the path of the eclipse installed in Step 2 – “C:\opt\eclipse”

8. Start eclipse and create a new Flex Project with server type PHP

9. Create/Import a new PHP service the flex project

10. Click on the filters icon at the top of the flex package explorer and uncheck some .* & .project

11. Create a .buildpath file right under the Flex Project and add the following content to it, take care not to overwrite the text in BOLD in your .project file:

<?xml version="1.0" encoding="UTF-8"?>

<buildpath>

<buildpathentry kind="src" path="services"/>

<buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/>

</buildpath>

12. Update your project’s .project file to look like this:
<?xml version="1.0" encoding="UTF-8"?>

<projectDescription>

<name>PdtFlexTest</name>

<comment></comment>

<projects>

</projects>

<buildSpec>

<buildCommand>

<name>org.eclipse.wst.validation.validationbuilder</name>

<arguments>

</arguments>

</buildCommand>

<buildCommand>

<name>org.eclipse.dltk.core.scriptbuilder</name>

<arguments>

</arguments>

</buildCommand>

<buildCommand>

<name>com.adobe.flexbuilder.project.flexbuilder</name>

<arguments>

</arguments>

</buildCommand>

</buildSpec>

<natures>

<nature>com.adobe.flexbuilder.project.flexnature</nature>

<nature>com.adobe.flexbuilder.project.actionscriptnature</nature>

<nature>org.eclipse.php.core.PHPNature</nature>

</natures>

<linkedResources>

<link>

<name>bin-debug</name>

<type>2</type>

<location>C:/projects/www/htdocs/PdtFlexTest-debug</location>

</link>

<link>

<name>services/TestService.php</name>

<type>1</type>

<location>C:/projects/www/htdocs/PdtFlexTest-debug/services/TestService.php</location>

</link>

</linkedResources>

</projectDescription>

13. Now click on the Debug menu and go to Debug configurations, create a new “PHP Web Page” debug configuration.

14. Click on debug, the browser will open and this debug session in PDT will wait for the service class to be invoked.

15. Now launch your flex application which uses this services, the PDT debugger should break at the first line of gateway.php. In case you would like the debugger to break on a breakpoint in the service class, uncheck the “Break at First Line” option in the Debug launch configuration and place a break point on the exact line in the service file where you would like the debugger to stop.

That’s all there is to it J. You can now edit your PHP code and Flex code in the same instance of eclipse. Full coloring, autocomplete and other PDT feature support for editing your PHP file in addition to all the awesome features of Flash Builder for editing you Flex applications J.

Enjoyyy!!!

6Jun/091

Howto: Use createItem method of the generated sample PHP file

Posted by

The generated sample PHP in FB has 5 methods/functions:

  • getAllItems()
  • getItem($itemID)
  • createItem($item)
  • updateItem($item)
  • count()
  • getItems_paged($startIndex, $numItems)

These methods help you easily use the client side data management functionalities of FB. Before we reach the final goal of using client side data management, we'll explore how these methods would be used conventionally.

My previous post explained how you can connect to the getAllItems() method of the generated file. This post I'll explain how to configure and use the createItem method.

Video - http://my.adobe.acrobat.com/p15003296/

Next post I'll cover delete and update.

Enjoyyy!!!

3Jun/091

Howto: Connect a flex application to database (for PHP developers)

Posted by

Setup:

1. Place employees.php file into wwwroot of your webserver.

2. Use this sql script to create the tutorial database (mysql -u<your db username> -p<your db password> < fb_tutorial_db.sql).

Typically, PHP scripts run on the server. The response of a PHP script is usually an HTML document which contains the UI/layout as well as the data. See employees.php in the attached tutorial zip file.

Flex applications, however, run in flash player in the browser (client). In order to fetch data from a database, the flex application needs to connect to some code running on the server which in turn connects to the database and returns the result. Hence, when developing flex applications, the PHP code can be freed from all UI constructs.

DCD workflows in FB4 make it very difficult for a PHP developer to face any problems in connecting a Flex Application to a PHP backend.

Here's a video (http://my.adobe.acrobat.com/p95044936/) which demonstrates the new workflow available for PHP users in FB4.

Some key points in the video:

  1. Create a new flex project (with server type selected as PHP)
  2. Open the Service Wizard and select PHP as your backend type
  3. Select the generate sample option and enter EmployeeService as the name for the service.
  4. When you click on finish a sample PHP file opens in your default PHP editor. This contains sample methods which can be implemented easily to get a functional PHP script which can be used with your flex application. For now you can copy the code from the attached EmployeeService.php file into your file that opened in the editor.
  5. Notice that all the methods of the PHP file are now shown in the Data/Services panel (also known as Services Explorer). Flex Builder introspects the PHP file and shows the structure in the Services Explorer. A notable fact is that the return types of all operations are marked as Object since return types are not specified in PHP files.
  6. A quick look at the file shows that the code written in the file is exactly the same code you would write anyway in a conventional PHP script, albeit its nested inside the methods of a PHP class. For now the names of the various methods in the file viz. getAllItems, getItemById, deleteItem, updateItem and getItems_paged may sound prescriptive, but bear with me for a couple posts to enter into a whole new world of flex applications with PHP.
  7. Now you can start authoring the flex application in FB using the WYSIWYG design view editor. Non-hierarchical tabular data (thats english for array of rows returned from a database table) can be displayed in a flex component called DataGrid. So drag and drop the datagrid onto the design surface.
  8. In order to display data in this grid, the PHP code on the server would have to be invoked so all you have to do is drag and drop the getAllItems operation onto the datagrid.
  9. When the operation is dropped onto the datagrid, the "Bind to Data" dialog prompts you to configure the return type of the operation. As a PHP developer you may find this concept may sound alienating. "Why the hell should I configure the return type of an operation ?" ... I hear you ... but again, bear with the step, its in your own interest. This step helps flex builder understand the structure of data that is returned by the operation, it enables stuff like code hinting on operation result, automatic setting up of data grid columns when operation is bound to the data grid and a lot of other stuff which we'll get into later.
  10. Once the return type has been configured and you click ok on the Bind to Data dialog, the datagrid automatically gets updated with the properties of the custom data type created in the "Configure Return Type" wizard.
  11. You just completed your first Flex application using PHP as the backend :) . Run it and see it for yourself ...

More to come in further posts...

Enjoyyy!!!

1Jun/091

Introduction to Data Centric Development in Flash Builder 4

Posted by

One of the cool new features in this release of Flash Builder 4 is the Data Centric Development (a.k.a. DCD).

These features enable simple workflows which will allow flex developers to quickly connect to their server side code and then author the UI in FB.

To get started with DCD features, I'll first go through some of the new options which are available in FB 4.

1. Your gateway to the world of services - the "Data/Services Panel" (a.ka. Services Explorer)

2. A new menu at the top of FB called the Data Menu. This will serve as your gateway to bringing in services into FB.

There are some other key components of the workflow but they make more sense when explained as a part of the workflow. The next post will have a demo which will show these components. Here's a list neverthless to enumerate them:

  • Configure Operation Return Type wizard: This wizard helps users configure the data that is returned by an operation.
  • Bind to Data Dialog: This dialog helps users connect the result of an operation to UI component in the MXML file.
  • Enable Paging Dialog: Get automatic paging support in your applications using this dialog ! :)
  • Enable Data Management Dialog: This is your gateway into a new feature (Client Side Data Management) as part of the DCD workflow. This allows all the data on the client side (your flex application) to be updated on the server side without the developer having to write explicit server update calls. It also provides for Highlander support. There features were earlier available for LCDS customers only. Now PHP users can also taste the benefits :) .
  • Form Generation: FB now supports Input/Output form generation and Master/Detail form generation through the use of simple wizards.

So long for now ... I'll be back with more posts on using the DCD workflows in FB4.

Enjoyyy!!!