Sencha:如何使用Ext.data.HttpProxy将参数传递给php?

时间:2012-12-17 16:57:16

标签: database list extjs store http-proxy

我已经成功完成了这个很棒的教程:http://www.sencha.com/learn/ext-js-grids-with-php-and-sql/

我只是不能使用代理指定的baseParams字段... 这是我的代码,遵循教程说明:

__ 我的商店:Communes.js __ _ _

Ext.define('app.store.Communes', {
    extend: 'Ext.data.Store',
    id: 'communesstore',
    requires: ['app.model.Commune'],

config: {
    model: 'app.model.Commune',
    departement:'var',

    // the proxy with POST method
    proxy: new Ext.data.HttpProxy({
        url: 'app/php/communes.php',      // File to connect to
        method: 'POST'
    }),

    // the parameter passed to the proxy
    baseParams:{
        departement: "VAR"
    },

    // the JSON parser
    reader: new Ext.data.JsonReader({   
        // we tell the datastore where to get his data from
        rootProperty: 'results'
    },
    [
        {
            name: 'IdCommune',     
            type: 'integer'
        },

        {
            name: 'NomCommune',    
            type: 'string'
        }
    ]),
    autoLoad: true,
    sortInfo:{
        field: 'IdCommune', direction: "ASC"
    }
}

});

__ _ __ php文件:communes.php _ ____

<?php

/**
 *  CREATE THE CONNECTION
 */
mysql_connect("localhost", "root", "pwd") or
        die("Could not connect: " . mysql_error());
mysql_select_db("databasename");

/**
 * INITIATE THE POST 
 */
$departement = 'null';
  if ( isset($_POST['departement'])){
    $departement = $_POST['departement'];   // Get this from Ext
  }

  getListCommunes($departement);

/**
 * 
 */
function getListCommunes($departement) {

[CODE HERE WORK FINE : just a connection and query but $departement is NULL]

}

?>

没有作为POST方法传递的参数......有什么想法吗?

1 个答案:

答案 0 :(得分:1)

因为baseParams是查询字符串的一部分,所以它们不会在POST主体中传递,而是在url中传递。

我不知道PHP,但可能有效:

if ( isset($_GET['departement'])){
    $departement = $_GET['departement'];   // Get this from Ext
}