Adobe Flex, WebORB for PHP and Qcodo

thread: 22 messages  |  last: about 4 years ago  |  started: tuesday, july 24, 2007, 11:36 am pdt


#1  |  Jurgen Beck (Dallas, TX) United States of America
Tuesday, July 24, 2007, 11:36 AM PDT

This may not be your normal post, but I believe we'll be seeing more of this kind of mash-up in the future.

Qcodo has such a great implementation for a full CRUD approach, that I want to implement it for use with WebORB for PHP and Adobe Flex as the presentation layer. This at the same time allows us to maintain web application functionality outside of Adobe Flex (aka non-RIA pages.)

WebORB for PHP is part of the data access layer, which takes the output of a SQL query and returns it to Adobe Flex as an object via RPC.

A lot of background to the following question:

What would you say is best practice of extending the Qcodo classes so that I can return the results of the actual SQL queries rather than returning an array?

Which classes would need to be extended?

Thanks,

Jurgen

#2  |  darkredz (KL) Malaysia
Wednesday, July 25, 2007, 1:27 AM PDT

Hi Jurgen. I am quite new to qcodo and is having problem with Qcodo + WebORB and AMFPHP.
I really like the code generator of Qcodo, it is smart!

I’ve tried including the prepend.inc.php at the beginning of my AMFPHP service classes. The error I get was: “PHP Error - A session had already been started - ignoring session_start()”.

I have tried with WebOrb too but it doesn't get any better. So, I have to rely on Qcodo to generate XML for me to be sent to Flex via HTTPService.

I really hope that there's a way for Qcodo to work with and these AMF toolkit.

#3  |  Jurgen Beck (Dallas, TX) United States of America
Wednesday, July 25, 2007, 10:42 AM PDT

Obviously, returning an array would be the easiest implementation. However, we loose quite a bit in terms of advanced concepts in Flex. Using AMF3 is the preferred way of getting large amounts of data back to Flex.

I'll keep digging and see if I can come up with a solution.

Jurgen

#4  |  Zbyszek Czarnecki (Warsaw, PL) Poland
Thursday, July 26, 2007, 11:57 AM PDT

You have to include modified version of qcodo prepend, one that doesn't start a session on initialization.

Below is minimal version of prepend without qforms.

i use it in my amfphp services and it works.

#5  |  Zbyszek Czarnecki (Warsaw, PL) Poland
Thursday, July 26, 2007, 11:59 AM PDT

<?php
   if (!defined('__PREPEND_INCLUDED__')) {
       // Ensure prepend.inc is only executed once
       define('__PREPEND_INCLUDED__', 1);

       require(dirname(_FILE_) . '/qcodo/qcodo_conf.inc.php');

       require(_QCODO_CORE_ . '/qcodo_orm_only.inc.php');

       abstract class QApplication extends QApplicationBase {
           public static function Autoload($strClassName) {
               // First use the Qcodo Autoloader
               parent::Autoload($strClassName);
           }

           public static $EncodingType = 'UTF-8';
       }

           QApplication::Initialize();
       QApplication::InitializeDatabaseConnections();
   }
?>

#6  |  Jurgen Beck (Dallas, TX) United States of America
Friday, July 27, 2007, 6:40 AM PDT

What are you returning with AMFPHP? Are you returning arrays or the SQL query results itself?

Jurgen

#7  |  darkredz (KL) Malaysia
Friday, July 27, 2007, 10:55 AM PDT

Hi klucznik, it works like magic!
Great! Thank you very much. Changing the prepend.inc.php does work magically.
However is that an older version of qcodo? I have slightly different code ()

<?php
   if (!defined('__PREPEND_INCLUDED__')) {
       // Ensure prepend.inc is only executed once
       define('__PREPEND_INCLUDED__', 1);


       require(dirname(_FILE_) . '/configuration.inc.php');

       require(_QCODO_CORE_ . '/qcodo.inc.php');

       abstract class QApplication extends QApplicationBase {
           public static function Autoload($strClassName) {
               // First use the Qcodo Autoloader
               parent::Autoload($strClassName);
           }

           public static $EncodingType = 'UTF-8';
       }

           QApplication::Initialize();
       QApplication::InitializeDatabaseConnections();
   }
?>

Once again thanks! Jurgen, I am sure it will work for you too. In my AMFPHP service, all I did is this:
require('C:/Apache/htdocs/qcodo/wwwroot/includes/prepend.inc.php');

#8  |  Jurgen Beck (Dallas, TX) United States of America
Friday, July 27, 2007, 11:06 AM PDT

That's great guys! Thanks for taking the time to figure this out.

Here is my question that I still have:

What are you eventually returning? An array, the direct MySQL query results?

Jurgen

#9  |  darkredz (KL) Malaysia
Friday, July 27, 2007, 11:31 AM PDT

Well, I can't return a query result to Flash by just calling MyObject::LoadAll();

Say I have an table call People with fields, 'id', 'name' and 'gender'.
Qcodo will generate a class: People.class.php
You would need to write a function that would return an assoc array of the fields available in People so that Flash/Flex can received it as ArrayCollection.

public function getAsArray(){
   return array(
       'id'=>$this->intId,
       'name'=>$this->strName,
       'isAssessment'=>$this->strGender
   );
}


In your AMF service class you can write a function like this:

public function getAllPeople(){
   $people = People::LoadAll();
   $rs=array();
   
   foreach ($people as $p){
          $rs[] = $p->getAsArray();
     }
   return $rs;
}

I am not sure is there any better method, this getAsArray function is tedious if you write for all of your tables. Maybe we should extend the code gen? Or is there any exisiting method to return an assoc array of the People instance?

#10  |  Jurgen Beck (Dallas, TX) United States of America
Friday, July 27, 2007, 11:40 AM PDT

See, that's the big difference between AMFPHP and WebORB. WebORB for PHP does all the dirty work for you. Here is an excerpt from an example of how WebORB handles the returned object and serializes the data into the right structure.

   // The getCustomers method retrieves data from the database and returns it to the requesting client.
   // Notice the return value data type - it is System.Data.DataTable. WebORB automatically converts
   // instances of the DataTable objects to arrays, so they can be used as data providers for
   // the components like DataGrid
   public function getCustomers()
   {
       $link = mysql_connect(“localhost”, “flexuser”, “password”);

       mysql_select_db('northwind', $link);

       $result = mysql_query(“SELECT * FROM Customers order by CustomerID;”)or die(“Invalid query: " . mysql_error());
       
       mysql_close($link);

       return $result;
   }

So, the question now is, how we alter Qcodo to support that methodology.

Jurgen



Copyright © 2005 - 2012, Quasidea Development, LLC
This open-source framework for PHP is released under the terms of The MIT License.