1. #1
    Sencha User TopKatz's Avatar
    Join Date
    Mar 2007
    Posts
    337
    Vote Rating
    1
    TopKatz is on a distinguished road

      0  

    Default Simple PHP with direct...

    Simple PHP with direct...


    I recently had a use for a direct setup. It was a for a grocery list builder basicaly. Navigate some lists of items and add them to a master list of items. Then allow for edit, remove, and also a batch add. I figured this was a good use for direct, and I was right.

    The problem was that I dont use a MVC or php frame work of any kind. All of my server side requests are handled in scripts that use a switch of sorts. In my request params I tell the server what Im trying to do, like:

    {"routine":"getClientInfo","clientID":1234}

    So as I looked into direct and how it worked with URI I was having a hard time figuring out how to deal with the writer API. Then I came up with the solution and figured I would share.

    So directs API looks something like this:
    Code:
     api:{
            read:'directRequest.php/readOrderItems',
            create:'directRequest.php/newOrderItem',
            update:'directRequest.php/updateOrderItem',
            destroy:'directRequest.php/deleteOrderItem'
        }

    The trick is to get the server to look at the last part of the URI, the answer was to use the php $HTTP_SERVER_VARS['PATH_INFO'] variable. This holds that path info in it. So on the server I just:

    PHP Code:
    $routine $HTTP_SERVER_VARS['PATH_INFO'];

    switch(
    $routine) {

         case(
    '/deleteOrderItem'):
            
    $recs       stripslashes($_POST['data']);
            
    $recs       json_decode($recs);
            
    $orderID    $_POST['orderID'];

            foreach (
    $recs as $rec) {
             
    mysql_query("DELETE FROM OrderItems
             WHERE orderItemID = '
    $rec'
             AND orderID = 
    $orderID")or $err mysql_error();
            }
            
             
    $response =  '{"success":true,"message":"Record updated for the Order!"}'

            print 
    $response;
            break;


    Hope this helps

    Katz

  2. #2
    Sencha User darren's Avatar
    Join Date
    Nov 2008
    Location
    Southern California
    Posts
    90
    Vote Rating
    0
    darren is on a distinguished road

      0  

    Default


    Interesting, thanks for sharing. Its really coll you can dictate the methods like that.

Thread Participants: 1