Results 1 to 5 of 5

Thread: Indicating CRUD action to a backend script

  1. #1
    Sencha User
    Join Date
    Jul 2009
    Posts
    30

    Default Indicating CRUD action to a backend script

    I am looking for what I expected to be a neater way to indicate to a store's URL script the type of operation it was called to perform. If I use the following in a proxy config within a store I can pass a parameter to the script as below:

    Code:
            api : {
                create  : 'cgi-bin/crud_script.pl?cmd=create',
                read    : 'cgi-bin/crud_script.pl?cmd=read',
                update  : 'cgi-bin/crud_script.pl?cmd=update',
                destroy : 'cgi-bin/crud_script.pl?cmd=destroy'
            }
    The above may be OK for one store, but it would make sense to have this as a standard for all stores. That way I could just use the url config item and know all scripts would be called the same way.

  2. #2
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,392
    Answers
    3997

    Default

    So you want just one place to specify this api but more importantly the urls?
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

  3. #3
    Sencha User
    Join Date
    Jul 2009
    Posts
    30

    Default

    I'm not sure I asked the right question to be honest. What I was trying to work out is how a CGI script knows whether it should, for example, fetch or delete data if the same script is used for all CRUD operations. For instance if the ExtJS makes a call and passes a parameter ID=1 how does it indicate to the backend to delete row 1 or get the data of row 1 in a database table.

  4. #4
    Sencha User
    Join Date
    Jun 2008
    Posts
    6
    Answers
    1

    Default

    You defined in the CRUD-Api section the same script with an cmd parameter to the script.

    Simply check in your script, which value the parameter "cmd" is and do the right action:

    In PHP:
    PHP Code:
    if('create' == $cmd) { 
      
    // do create record stuff }
    if('read' == $cmd) {
      
    // read record stuff
    }
    if(
    'update' == $cmd) {
     
    // create record stuff
    }
    if (
    'delete' == $cmd) {
      
    // delete record stuff} 
    In your example the cmd parameter is an GET paramenter => $_GET['cmd'] in PHP.

  5. #5
    Sencha User
    Join Date
    Jul 2009
    Posts
    30

    Default

    Many thanks for the reply SkyBlader. I understand that the config below will pass the parameters as you said.

    Code:
    api : {             
        create  : 'cgi-bin/crud_script.pl?cmd=create',             
        read    : 'cgi-bin/crud_script.pl?cmd=read',            
        update  : 'cgi-bin/crud_script.pl?cmd=update',             
        destroy : 'cgi-bin/crud_script.pl?cmd=destroy'         
    }
    What I'm puzzled by is my expectation that ExtJS would set a parameter automatically indicating create, read, update or destroy. I was looking for this in the documentation and couldn't find it. So I've either missed something or there is no automatically passed parameter. In the latter case the above would work, but I wonder if this the the best approach.

Posting Permissions

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