2 Replies Latest reply on Jul 20, 2011 4:08 PM by kokorito

    Flex (FB4.5) with PHP (hopefully referenced to zendAMF)

    Energetic Pixels Level 1

      OK, I can find examples all day long of a flex application being used with php/mysql (to include some kind of AMF feature).  But come on, how many databases are built in the real world with just a single table in them???

       

      Does anyone know of a source that shows an example of how to use a real world example database (2 or more tables) with flex???

       

      I am sort of lost on my application build and could use an example ("To apply power to the lightbulb" in my head).

       

      Tony

        • 1. Re: Flex (FB4.5) with PHP (hopefully referenced to zendAMF)
          kokorito Level 4

          you can use as many tables or databases as you want. Thats a server side issue that Flex isnt interested in. You just send the data to the server and its up to php as to where it saves it.

          Same when fetching data, php queries the tables, prepares the data and sends it to flex. Flex doesnt need to know what happenes server side

          • 2. Re: Flex (FB4.5) with PHP (hopefully referenced to zendAMF)
            kokorito Level 4

            an example of how I do it

            I want to return an array of users to flex. I would start by making a user object in php.

             

             

            <?php

             

            class VO_User
            {
                /**
                 *
                 * user id number
                 * @var int
                 */
                var $userid;
               
                /**
                 * user login name
                 * @var string
                 */
                var $login;
               
                /**
                 *
                 * user first name
                 * @var string
                 */
                var $firstName;
               
                /**
                 *
                 * user last name
                 * @var string
                 */
                var $lastName;
               
            }

             

             

            This is the class the method to return the users

             

             

            <?php

             

            require_once 'valueObjects/VO_User.php';

             

            class ExampleService
            {
               
                /**
                 *
                 * returns and array of the users
                 * fetches id and login name from the users table
                 * fetches first name and last name from the personel table
                 *
                 * return declaration for flex, an array of VO_User objects
                 * @return VO_User[]
                 */
                public function getAllUsers()
                {
                   
                   
                    $query = "SELECT users.id as user_id,
                            users.login as login_name,
                            personel.firstname AS first_name,
                            personel.lastname AS last_name
                            FROM users
                            LEFT JOIN personel ON users.id=personel.id";
                   
                   
                    //do the mysql connection
                    //and query stuff
                    //...
                   
                   
                    $returnArray = array();
                   
                    while($line = $result->fetch_array(MYSQLI_ASSOC))
                    {
                        $user = new VO_User();
                        $user->userid = $line['user_id'];
                        $user->login = $line['login_name'];
                        $user->firstName = $line['first_name'];
                        $user->lastName = $line['last_name'];
                       
                        $returnArray[] = $user;
                    }
                   
                   
                    return $returnArray;
                }
               
            }

             

             

             

            Notice the use of declartion block above the method, when you connect to the service from flex, the @returns declation tells flex what to expect back. Also the @var declartons before the variables in the VO_User class. Once again telliing flex what to expect. That allows flex to generate the valueObjects in actionscript.

            You can use php to build the return objects anyway you want.