将php值发送到extjs中的另一个文件

时间:2012-06-08 16:32:34

标签: php extjs4

我需要使用extjs4将php变量的值传递给另一个文件 我在页面顶部有这个:

$userid = $_POST['userid'];

这是我的extjs代码

echo("
{
    title: 'Users',
    xtype: 'gridpanel',
    autoScroll: true,
    layout: 'fit',
    store: {
        storeId: 'test',
        fields: [
            {name: 'ID', type: 'string'},
            {name: 'Name', type: 'string'},
            {name: 'Admin', type: 'string'}
        ],
        proxy: {
            type: 'ajax',
            url : 'GetScripts/getUsers.php',
            reader: 'json'
        },
        autoLoad: true
    },

我需要将$ userid传递给getUsers.php。 我可以帮忙解决这个问题吗?

1 个答案:

答案 0 :(得分:2)

在您的代理中,您可以指定URL参数,如下所示:

echo("
{
    title: 'Users',
    xtype: 'gridpanel',
    autoScroll: true,
    layout: 'fit',
    store: {
        storeId: 'test',
        fields: [
            {name: 'ID', type: 'string'},
            {name: 'Name', type: 'string'},
            {name: 'Admin', type: 'string'}
        ],
        proxy: {
            type: 'ajax',
            url : 'GetScripts/getUsers.php',
            reader: 'json',
            extraParams: { 
               userid: " . $userid . "
            }
        },
        autoLoad: true
    },

此外,当您加载商店时,您也可以传递参数

store.load({
    params : {
       userid : whateverUserId
    }
});