1. #1
    Sencha User
    Join Date
    Dec 2012
    Posts
    5
    Vote Rating
    0
    ssenlighta is on a distinguished road

      0  

    Default Unanswered: A problem of specifying two or more methods of a PHP class on a server from a store

    Unanswered: A problem of specifying two or more methods of a PHP class on a server from a store


    Hi friends,
    Could anyone help me what can I here:
    1. I have one store specifies proxy(type=ajax) and its url (both (server) controller and its method(function))
    2. And through this url I am specifying (PHP) controller method which loads data from database to display in the grid
    3. Now I have a form that should insert(not working) some related data (in grid) into database
    4. I have got my code snippets like this:
    This code from the client controller->
    Code:
     addAssignment: function(button){        if(this.getForm().getForm().isValid()){
            var win = button.up('window'),
            form = win.down('form');
            var values = form.getValues();
            //here we are in need of the a model instance of the current one
           // grid.store.insert(0, values);
            url:this.application.getUrl('addusertrafficlog')
            this.getUserlogStore().insert(0, values);
            win.close();
            this.getUserlogStore().sync();
            //writer
            this.getUserloggrid().getStore().reload();    
        }
    This code from the store:
    Code:
     proxy: {      type: 'ajax',
         url: Server.getUrl('Module.network.userlog','trafficLog'),
          reader: {
          type: 'json',
          root: 'trafficlog',
          //totalProperty:'count',
          listeners:{
              exception: Server.createReaderExceptionCallback()
          }
        },
        //here we have to specify writer for for record writing
          writer: {
                type: 'json',
                //find what root does 
                // url: Server.getUrl('Module.network.userlog','addUserTrafficLog'),
                root: 'logupdate',
                listeners: {
                    exception: Server.createFormFailureCallback()
                }
          },
        actionMethods:{
            read:'POST'
         },
    This code from the server controller->
    Code:
    <?php
    
        class UserlogController extends ModuleApp{
            
            
            public function actionTrafficLog (){
                
                //this command variable stores values using dbCommand of the parent controller by this  
                
                $command = $this->dbCommand();//here you ing see that we using moduleApp as a  base controller 
                $command->select(array(
                    'ut.id',
                    'ut.ip',
                    'ut.start_date',
                    'ut.end_date',
                    'ut.status'
                ))->from('user_traffic_log ut')
                  ->where('is_deleted = false');
                  $this->applyPaging($command);
                  $this->applySort($command, 'id DESC');
                  $trafficlog = $command->queryAll();
                  //this result method of the Controller specifies data send to the client 
                  $this->result(array('trafficlog'=>$trafficlog));
            }
            
            //from here on we should we would like to craete an action that serves as method for retrieving data from database 
            //for traffic log info 
            public function actionAddUserTrafficLog(){
    
    
                $json = file_get_contents('php://input');
                
                $data = CJSON::decode($json);
                var_dump($json);
                die;
                //$data = $_POST;
                $command = $this->dbCommand();
                //keep inmind that calling a insert function of the dbCommand, we should specify table name as a first parameter 
                // and as a second paramter colums or array values 
                $result = $command->insert('user_traffic_log', array(
                 'ip'=>$data['ip'],
                  'start_date'=>$data['start_date'],
                  'end_date'=>$date['end_date'],
                  'status'=>$data['status'],
                  'is_deleted'=>$data['is_deleted'] 
                    
                ));
               // $logupdate = $command->queryAll();
                $this->result(array('logupdate'=>$result));
            }
            
        }
    
    
    
    
    ?>
    Thank you in advance

  2. #2
    Sencha User existdissolve's Avatar
    Join Date
    Jan 2010
    Location
    Kansas
    Posts
    522
    Vote Rating
    86
    Answers
    31
    existdissolve is just really nice existdissolve is just really nice existdissolve is just really nice existdissolve is just really nice existdissolve is just really nice

      0  

    Default


    Two easy ways:

    Easiest with what you have: Use the proxy's api config to specify the endpoints that should be used for CRUD operations.

    Less easy, but more elegant (IMO): Use the Rest proxy. It will auto generate endpoints and HTTP verbs based on the particular CRUD action.

Thread Participants: 1