将值从Store传递给PHP

时间:2013-07-08 08:58:07

标签: sencha-touch sencha-touch-2 sencha-architect

我正在尝试将值传递给PHP服务器端。我的商店代码如下;

Ext.define('MyApp.store.MyArrayStore', {
    extend: 'Ext.data.Store',

    requires: [
        'MyApp.model.MyMOD'
    ],

    config: {
        autoLoad: true,
        model: 'MyApp.model.MyMOD',
        storeId: 'MyArrayStore',
        proxy: {
            type: 'ajax',
            actionMethods: 'POST',
            url: 'http://localhost/mm/app/php/res.php',
            reader: {
                type: 'json'
            }
        },
        listeners: [
            {
                fn: 'onArraystoreBeforeLoad',
                event: 'beforeload'
            }
        ]
    },

    onArraystoreBeforeLoad: function(store, operation, eOpts) {
        this.proxy.extraParams.VALUES1 = "pass some name here"; 
    }

});

PHP代码

<?php
error_reporting(E_ERROR | E_PARSE);

require_once 'conn.php'; // contains the connection

$v = $_POST['VALUES1'];
echo json_encode($v);

?>

返回的是null,而不是我从商店传递的值(pass some name here)。

我该如何纠正?

更新

Request URL:http://localhost/test/app/php/res.php?_dc=1373343459447
Request Method:POST
Status Code:200 OK
Request Headersview source
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:23
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Host:localhost
Origin:http://localhost
Referer:http://localhost/test/app.html
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36
X-Requested-With:XMLHttpRequest
Query String Parametersview sourceview URL encoded
_dc:1373343459447
Form Dataview sourceview URL encoded
page:1
start:0
limit:25
Response Headersview source
Connection:Keep-Alive
Content-Length:24
Content-Type:text/html
Date:Tue, 09 Jul 2013 04:17:39 GMT
Keep-Alive:timeout=5, max=96
Server:Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_perl/2.0.4 Perl/v5.10.1
X-Powered-By:PHP/5.3.1

2 个答案:

答案 0 :(得分:2)

您需要更改设置extraParams的方式..在这种情况下我将使用

  store.getProxy().setExtraParam('VALUES1','pass some name here');

如果您需要发送多个参数,请使用setExtraParams

  var param = { VALUES1: 'param1', VALUES2 : 'param2'};
  store.getProxy().setExtraParams(param);

如此完整的商店代码

Ext.define('MyApp.store.MyArrayStore', {
    extend: 'Ext.data.Store',

    requires: [
        'MyApp.model.MyMOD'
    ],

    config: {
        autoLoad: true,
        model: 'MyApp.model.MyMOD',
        storeId: 'MyArrayStore',
        proxy: {
            type: 'ajax',
            actionMethods: 'POST',
            url: 'http://localhost/mm/app/php/res.php',
            reader: {
                type: 'json'
            }
        },
        listeners: [
            {
                fn: 'onArraystoreBeforeLoad',
                event: 'beforeload'
            }
        ]
    },

    onArraystoreBeforeLoad: function(store, operation, eOpts) {
        store.getProxy().setExtraParam('VALUES1 ','pass some name here');
    }

});

答案 1 :(得分:1)

而不是this.proxy尝试this.getProxy()

我发现控制台对于这类事情非常有用。在我自己的应用程序中运行Ext.getStore('MyStore').proxy;让我未定义,而Ext.getStore('MyStore').getProxy()让我成为我的代理。

使用控制台,对我而言,它是API旁边最有价值的开发工具。

祝你好运,布拉德