PDA

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



ssenlighta
28 Dec 2012, 11:51 PM
Hi friends,
Could anyone help me what can I here:

I have one store specifies proxy(type=ajax) and its url (both (server) controller and its method(function))
And through this url I am specifying (PHP) controller method which loads data from database to display in the grid
Now I have a form that should insert(not working) some related data (in grid) into database

I have got my code snippets like this:
This code from the client controller->
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:
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->
<?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

existdissolve
29 Dec 2012, 8:27 AM
Two easy ways:

Easiest with what you have: Use the proxy's api config (http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.proxy.Ajax-cfg-api) to specify the endpoints that should be used for CRUD operations.

Less easy, but more elegant (IMO): Use the Rest proxy (http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.proxy.Rest). It will auto generate endpoints and HTTP verbs based on the particular CRUD action.