6 Replies Latest reply on Jul 6, 2011 1:18 AM by lucsc

    FLEX PHP RPC

    lucsc

      Hi all,

       

      (sorry for my bad english)

       

      I'm working with flex 4 sdk and I tried to integrate flex and php with rpc.

      I have a little problem with this architecture. The problem is:

       

      I have table called 'user' in sql with columns: userid, email, password.

      I've created simple flex app. Flex created for me AS code and PHP code with DATA\SERVICES.

      I have methods:

      -count()

      -createUser(item:User):int

      -getAllUser():User[]

       

      If I want to select all users I have in my db I'm drag and drop getAllUser() method on DAtaGrid and configuring creation complete on datagrid.

      Everything is OK. RPC is OK.

       

      But...

      If I want to create user with createUser method I must have the 'item' type 'user' from valueobject.

      I created the item in AS code. I also update my flex code with button with click method generated automatically.

      My problem is the RPC not created new user in my db.

      But if i choose test operation it;s working.

       

      my code below:

      php

          public function createUser($item) {

       

              $stmt = mysqli_prepare($this->connection, "INSERT INTO $this->tablename (email, password) VALUES (?, ?)");
              $this->throwExceptionOnError();

       

              mysqli_stmt_bind_param($stmt, 'ss', $item->email, $item->password);
              $this->throwExceptionOnError();

       

              mysqli_stmt_execute($stmt);       
              $this->throwExceptionOnError();

       

              $autoid = mysqli_stmt_insert_id($stmt);

       

              mysqli_stmt_free_result($stmt);       
              mysqli_close($this->connection);

       

              return $autoid;
          }

       

      as

          public function createUser(item:valueObjects.User) : mx.data.ItemReference
          {
              var _internal_operation:mx.rpc.AbstractOperation = _serviceControl.getOperation("createUser");
              var _internal_token:mx.data.ItemReference = _internal_operation.send(item) as mx.data.ItemReference;

       

              return _internal_token;
          }

       

      flex

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

      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

                     xmlns:s="library://ns.adobe.com/flex/spark"

                     xmlns:mx="library://ns.adobe.com/flex/mx"

                     minWidth="955" minHeight="600" currentState="home" xmlns:userservice="services.userservice.*">

       

          <fx:Script>

       

                  import mx.controls.Alert;

                  import valueObjects.User;

                  protected function button_clickHandler(event:MouseEvent):void

       

                  {

       

                      var item : User;

       

                      item.email = 'asd';

       

                      item.password = 'asd';

       

                      createUserResult.token = userService.createUser(item);

       

                  }

      </fx:Script>

       

          <fx:Declarations>

              <s:CallResponder id="createUserResult"/>

              <userservice:UserService id="userService" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/>

          </fx:Declarations>

       

          <s:Group x="0" y="0" width="100%" height="100%">

       

              <s:Button includeIn="home" x="102" y="246" label="create" id="button" click="button_clickHandler(event)"/>

          </s:Group>

       

      </s:Application>

       

       

      any ideas, helps and solutions are helpful

        • 1. Re: FLEX PHP RPC
          Chris.1234

          I have the same problem!

           

          Did you solve it?

          1 person found this helpful
          • 2. Re: FLEX PHP RPC
            lucsc Level 1

            Hi Chris.

             

            I was thinkin' a lot of time to solve this.

            And I get an answer.

             

            Instead of using zend i user amfphp from official.

            They got very simple documentation and a lot of samples which works.

             

            If You want more infos/code sample (mine) write reply.

             

            Ciao

            • 3. Re: FLEX PHP RPC
              Chris.1234 Level 1

              Here is a nice tutorial:

              http://www.adobe.com/devnet/flex/testdrive/articles/2_modify_the_database.html?PID=4176632

               

              But an alternative is also very nice

              Can you send more infos etc?!

               

              Thx..

               

              Mit freundlichen Grüßen / Kind regards

              Christian Meurisch

               

              Am 05.07.2011 23:29, schrieb lucsc:

              Hi Chris.

                 

              I was thinkin' a lot of time to solve this.

              And I get an answer.

                 

              Instead of using zend i user amfphp from official.

              They got very simple documentation and a lot of samples which works.

                 

              If You want more infos/code sample (mine) write reply.

                 

              Ciao

              >

              • 4. Re: FLEX PHP RPC
                kokorito Level 4

                you havent instantiated the item

                 

                var item:User = new User();

                • 5. Re: FLEX PHP RPC
                  Chris.1234 Level 1

                  Yeeah, that's right!

                   

                  But this wasn't the solution of the problem...

                   

                  Problem is that the data service call (only create & update - generated

                  php method and service calls by flash builder) doesn't leave the flash

                  player tho' the send method will be called!

                   

                  When I try the TestOperation of Flash Builder, it works! -> mysterious =)

                   

                  Mit freundlichen Grüßen / Kind regards

                  Christian Meurisch

                   

                  Am 06.07.2011 01:28, schrieb kokorito:

                  you havent instantiated the item

                     

                  var item:User = new User();

                  >

                  • 6. Re: FLEX PHP RPC
                    lucsc Level 1

                    Yeap.

                    You're right. I forgot initialize new User().

                    Main thing witch isn't created using auto generated flash builder service calls is class mapping between PHP classes and AS3 classes.

                     

                    I dont use zend becasu it's very advance.

                    I use simple amfphp from official website. ( try google )

                     

                    If You need I can share my code with You.

                    ciao