Results 1 to 8 of 8

Thread: A Simple DataWriter

  1. #1
    Sencha User
    Join Date
    Jun 2007
    Posts
    46
    Vote Rating
    6
      0  

    Default A Simple DataWriter

    I haven't seen anything like this yet, which surprised me. Here is a simple DataWriter for those who want to have their parameters in HTTP POST fashion, instead of a glob of JSON or XML. It works for me, use at your own risk.

    PHP Code:

    /*
     * File: Ext.ux.data.HttpWriter.js
     * Date: 11-Mar-2010
     * By  : Kevin Esteb
     *
     * A DataWriter that renders the parameters in standard HTTP POST fashion.
     *
     * kesteb(at)wsipc.org
     *
     * Use and abuse as you see fit, but please leave this attribution.
     * Thank you.
     *
     */

    Ext.namespace('Ext.ux.data');

    Ext.ux.data.HttpWriter Ext.extend(Ext.data.DataWriter, {

        
    constructor: function(config) {
            
    Ext.ux.data.HttpWriter.superclass.constructor.call(thisconfig);
        },

        
    render: function(paramsbaseParamsdata) {
            
    Ext.apply(paramsbaseParams);
            for (var 
    x in data) {
                
    params[x] = data[x];
            }
        },

        
    createRecord: function(rec) {
           return 
    this.toHash(rec);
        },

        
    updateRecord: function(rec) {
            return 
    this.toHash(rec);
        },

        
    destroyRecord: function(rec) {
            var 
    data = {};
            
    data[this.meta.idProperty] = rec.id;
            return 
    data;
         }

    }); 

  2. #2
    Sencha User
    Join Date
    Mar 2008
    Posts
    566
    Vote Rating
    0
      0  

    Default

    I have not looked at data writer for this reason. I will try soon.

    Marty

  3. #3
    Sencha User TopKatz's Avatar
    Join Date
    Mar 2007
    Posts
    340
    Vote Rating
    2
      0  

    Default

    This is cool,

    however this was less of an issue then the api, and that it uses a URI. I eventually worked around the URI issue by using the HTTP_SERVER_VARS['PATH_INFO'] variable in php. The data blob can just be decoded on the server side.

    Katz

  4. #4
    Sencha User
    Join Date
    Mar 2008
    Posts
    566
    Vote Rating
    0
      0  

    Default

    Katz,

    I was hoping to try this today, what is URI? Do you mean url?

    BLOB? The data writer just post data to the server via post or get, right?

    Marty

  5. #5
    Sencha User TopKatz's Avatar
    Join Date
    Mar 2007
    Posts
    340
    Vote Rating
    2
      0  

    Default

    URI is part of the URL. In the api with this it basically goes like :

    your/path/file.php/someAction

    So because Im not using a MVC I needed to read the someAction part to do my work. Using the PATH_INFO I'm able to use the "someAction" part and switch on that to handle the different acctions.

    It does use POST or GET, it just uses a data object (blob) with sub objects in it. This UX breaks out the "data" blob into traditional post items.

    Again, for me dealing with the data object was not a issue. Handling the api part was what took me some time to figure out how to deal with.

    There is a good writer example in the grid section that I found helpful

    Katz

  6. #6
    Sencha User
    Join Date
    Mar 2008
    Posts
    566
    Vote Rating
    0
      0  

    Default

    Thanks, I am not using MVC either.

    Can I do something like:

    update: {
    url: 'mypage.asp',
    method: "DELETE",
    params:{
    type: 'update'
    }
    }

    Or add ?type=update to my url?

    I will check out the grid example.

    Marty

  7. #7
    Sencha User TopKatz's Avatar
    Join Date
    Mar 2007
    Posts
    340
    Vote Rating
    2
      0  

    Default

    I was unable to gt it to submit the "type" as a post param with out using a baseParam. Thats why I ended up using the path stuff. So in your api it would look like this:

    update:'mypage.asp/updateSomeThing'

    then you just switch on the "updateSomeThing" part

  8. #8
    Sencha User
    Join Date
    Jun 2007
    Posts
    46
    Vote Rating
    6
      0  

    Default

    I wrote this because I wanted a consistent presentation of parameters to the back end. Having a special case of "data" that needs to be decoded, is not worth the effort in my opinion.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •