0

I want to pass a combobox value to a PHP file that'll execute a mySQL query. I'm using Extjs 4 with the MVC architecture. This is my combobox :

{
            xtype: 'combobox',
            id: 'cmbMetric',
            name: 'sev',
            mode: 'queryMode',
            //querymode : 'lcoal',
            fieldLabel: 'Metric',
            store: 'MetricsData',
            editable: false,
            valign : 'middle',
            margin : 15,
            displayField:'name_metric',
            valueField : 'id_metric'

        }

My store :

Ext.define('Metrics.store.GuiData', {
extend: 'Ext.data.Store',
model: 'Metrics.model.GuiData',
autoLoad: true,
idProperty: 'id_metric',
proxy : {
    type : 'ajax',
    actionMethods : 'POST',
    api : {
    read : 'gui_comp_items.php'
    },
    reader: {
        type: 'json',
        successProperty: 'success',
        messageProperty: 'message',
        root: 'data'
    }
}
});

When I choose a combobox value, this function is called by the controller :

    onSelectedValue : function(combo) {
    var selected = combo.getValue();
    var guiDataStore = this.getGuiDataStore();
    guiDataStore.getProxy().url = 'gui_comp_items.php?id_metric=' + selected ;
    guiDataStore.load({
    params : {
        id_metric : selected //The parameter I want to send to the php file         
        },
        callback:this.onGuiDataLoad, 
        scope: this
    });
}

My php file :

 function guiCompItems() 
{
$id_metric = $_GET['id_metric'];
    $sql = 'select m.id_metric, f.name_filter, gui.type_guicomp from gui_comp gui inner join   filter f inner join metric m
         on f.id_guicomp = gui.id_guicomp 
         and f.id_metric = m.id_metric
         where m.id_metric ='. mysql_real_escape_string(trim(intval($_GET['id_metric'])));   
$result = mysql_query($sql); // result set   
while($rec = mysql_fetch_array($result, MYSQL_ASSOC)){
    $arr[] = $rec;
};

$data = json_encode($arr);  //encode the data in json format
echo '({"success": "true", "message" : "OK","data":' . $data . '})';
}

The data is always "null". I think that the parameter is not sent to the php file. Any help would be much much appreciated. Thanks.

salamey
  • 3,633
  • 10
  • 38
  • 71

1 Answers1

0

Store load doesn't actualy encode the params config in the request. The request is made by the proxy configured for the store so any other params you need to send should be set in the proxy's extra params config. Like:

guiDataStore.getProxy().url = 'gui_comp_items.php?id_metric=' + selected ;
 guiDataStore.getProxy().extraParams = {
        id_metric : selected //The parameter I want to send to the php file         
        };
guiDataStore.load({
        callback:this.onGuiDataLoad, 
        scope: this
    });
nscrob
  • 4,483
  • 1
  • 20
  • 24