Hybrid View

  1. #1
    Sencha User
    Join Date
    Sep 2007
    Location
    Tulsa, Oklahoma
    Posts
    178
    Vote Rating
    1
    ckr is on a distinguished road

      0  

    Cool Ext.Direct PHP backend

    Ext.Direct PHP backend


    1/25/2010
    Found a few bugs when working with Ext-3.1.0 (my mistakes, not Ext's). Updated the zip file. You should be able to unzip into your examples directory (in your Ext install), and run from there.

    Biggest change was due to my incorrect handling of the formHandler value required by the API. So that the API generator can detect that a particular method is a form handler, you need to add frmHandler to your method name. You can see the comments in the Profile.php class file. There was really no way that I could see of getting that info using Reflections. Someone smarter than me may have a better idea here.

    Remember the main goal (at least for me) was to simply write the php code, and then have the config and api generated from the classes, instead of having to manually create and maintain them.

    Demo is working with 3.1 just fine, and the demo link below has been updated to the Ext-3.1.0 version.

    ---------------------------------------------------------------------------------
    7/11/2009
    Missed a variable name change in the before and after calls.
    Fixed.

    7/9/2009
    Fixed router for multiple arguments in actions (finally). I misunderstood what was happening there. But this should be good to go now.

    Zip has been updated.
    Demo here.
    ---------------------------------------------------------------------------------
    6/17/09
    Fixed router to better handle parameters
    Update demo page (with form, and tree examples)

    Updated the attachment with latest changes.
    ---------------------------------------------------------------------------------

    6/5/09
    Fixed router to handle parameters properly
    Fixed utils to handle multiple server action classes

    Updated the attachment with latest changes.

    ---------------------------------------------------------------------------------
    Ext.Direct PHP backend
    First I am not a developer, more of a guy that likes to hack around. So this is by no means and end all solution. In fact, it might just be drivel. But while working with the examples and attempting to see how I could do some comet long polling stuff, I have re-worked the PHP backend for Ext.Direct just a bit.


    Might want to save your originals before unzipping.
    Attached Files
    Last edited by ckr; 5 Jan 2012 at 2:58 PM. Reason: New URL - Things are working again!!
    Thanks!
    Chuck

  2. #2
    Sencha User
    Join Date
    Sep 2007
    Location
    Tulsa, Oklahoma
    Posts
    178
    Vote Rating
    1
    ckr is on a distinguished road

      0  

    Default


    **Updated*** So that this is more functional (the previous post is blah)

    First thing to note however, is if you need a really robust solution, I would suggest looking at Tommy's solution here. So maybe this should be viewed as a "Lite" implementation.

    I was looking for something a little more lightweight and less involved. So I completely rewrote the previous approach. This now supports the len, and the before and after calls. All you do is build your actions class in PHP, and plop it in the proper directory. I used this reference as a guide for working with Reflections in PHP.

    The router.php is very similar to the example one provided with the release. I have added some comments, but the only portion that I really altered was the RPC portion. That has been completely redone.

    baseAPI.php has been replaced by extBaseProvider.php and there is now a small additional utils.php file.

    The attachment can be unzipped in the examples/direct/ directory (make a backup of yours first). Be sure to read the embedded comments for additional info. Maybe this will help someone. Just thought I would share.
    Thanks!
    Chuck

  3. #3
    Sencha User
    Join Date
    Sep 2007
    Location
    Tulsa, Oklahoma
    Posts
    178
    Vote Rating
    1
    ckr is on a distinguished road

      0  

    Default


    Here is a demo using the above. The chart update portion is taken from here, but re-written using Ext.Direct, and this PHP back end.
    Last edited by ckr; 4 Jan 2014 at 7:55 PM. Reason: updated url
    Thanks!
    Chuck

  4. #4
    Sencha User
    Join Date
    Sep 2007
    Location
    Tulsa, Oklahoma
    Posts
    178
    Vote Rating
    1
    ckr is on a distinguished road

      0  

    Default


    Since I never heard anything on this and now that we have some better examples with 3.0RC2, there is one change that is needed in the utils.php to support multiple server side action classes. Red code is removed, Blue is the replacement.

    utils.ph - function buildAPI
    Code:
    function buildAPI($myObj)
    {
       $myClass = new ReflectionClass($myObj);
       $myProp  = array();
       $data    = array();
    
       foreach(array_values($myClass->getProperties()) as $property)
       {
          if ($property->isPublic())
          {
             $propName  = $property->name;
             $propValue = $property->getValue($myObj);
    
             if ((!is_object($propValue))&&(!is_array($propValue)))
             {
                $data[$propName] = $propValue;
             }
             else
             {
                // Added this bit, in the event that this
                // should be an array (which I think it should be
                // but for now will leave as is)
                //
                if (is_object($propValue))
                {
                   $data[$propName] = getActions($propValue);
                }
                elseif (is_array($propValue))
                {
    
                   foreach($propValue as $obj)
                   {
                       $data[$propName][] = getActions($obj);
    
                      if (!array_key_exists($propName, $data))
                      {
                         $data[$propName] = getActions($obj);
                      }
                      else
                      {
                         $data[$propName] = array_merge($data[$propName], getActions($obj));
                      }
    
                   }
                }
                else
                {
                   die("Unexpected data type encountered...");
                }
             }
          }
       }
       return $data;
    }
    This change basically flattens the array of the server classes, so that when the JSON is built, it adds the server classes as a property to the Ext.RemotingProvider actions object.

    Once this change is in place, all of the new demos work.
    Thanks!
    Chuck

  5. #5
    Sencha User
    Join Date
    Sep 2007
    Location
    Tulsa, Oklahoma
    Posts
    178
    Vote Rating
    1
    ckr is on a distinguished road

      0  

    Default


    See first post for new attachment with latest fixes.
    Thanks!
    Chuck

  6. #6
    Sencha User
    Join Date
    Sep 2007
    Location
    Tulsa, Oklahoma
    Posts
    178
    Vote Rating
    1
    ckr is on a distinguished road

      0  

    Default


    Another small update to the router when passing more than one parameter.

    Updated the demo page here, all using this interface.

    Updated the zip on the first post.
    Thanks!
    Chuck

  7. #7
    Ext User
    Join Date
    Sep 2007
    Posts
    13
    Vote Rating
    0
    Cambiata is on a distinguished road

      0  

    Default Download zip out of sync with online demo?

    Download zip out of sync with online demo?


    Hi! Great lib!

    It seems like the php-lib download is out of sync with your direct-demo though.

    1. JavaScript error: out.el not defined (Might be caused by the current 3.1?)
    2. There seems to be missing actions for fileList, updateChart etc...

    Corrections or new exciting versions in the pipe? :-)

    Regards / Jonas

  8. #8
    Sencha User
    Join Date
    Sep 2007
    Location
    Tulsa, Oklahoma
    Posts
    178
    Vote Rating
    1
    ckr is on a distinguished road

      0  

    Default


    Hey Cambiata. Thanks for the heads up.

    Real work has been keeping me busy. I will look into it and let you know.
    Thanks!
    Chuck

  9. #9
    Sencha User
    Join Date
    Sep 2007
    Location
    Tulsa, Oklahoma
    Posts
    178
    Vote Rating
    1
    ckr is on a distinguished road

      0  

    Default


    Ok - So the out.el not defined was simply an error when attempting to write out to the status window before it was actually rendered. So now when you load the demo page, you will see the status window (some might not have even noticed that it was there), and then it will collapse. You can expand it at any time. I have dumped this demo in my 3.1 install and everything is work fine.

    I did make a few small changes, see the first post in this thread.

    Enjoy!
    Thanks!
    Chuck

  10. #10
    Ext JS Premium Member
    Join Date
    Mar 2007
    Location
    Germany
    Posts
    671
    Vote Rating
    0
    Dumbledore is on a distinguished road

      0  

    Default


    Hi,

    i can´t figure out how to handle PHP-Sessions with your Ext.Direct Implementation.
    Can you offer an example?

    Bye, Dumbledore