1

我在 extjs+Yii 工作。我的客户端功能在 yii 中设计,服务器端功能在 extjs 中。在 extjs 控制器中,我编写了代码来动态发送生成存储,设置其代理并使用存储的 sync() 方法。

 review:function()
    {  var reviewQuestionStore=Ext.create('Balaee.store.qb.QbqnsStore');
        proxy=reviewQuestionStore.getProxy();
        Ext.apply(proxy.api,{
            read:'http://127.0.0.1/s_balaee/Balaee/index.php/QuestionBank/Qbpaper/ReviewQuestionPaper',
            create:'http://127.0.0.1/s_balaee/Balaee/index.php/QuestionBank/Qbpaper/ReviewQuestionPaper',
        });
        Ext.apply(proxy.writer,{
            type:'json',
            root:'records'
        });

        Ext.apply(proxy.reader,{
            type:'json',
            root:'questions'
        });
        var getdata=this.getLocalvalue();
            UserId=getdata.data.userId;

        //Using sync method
        var check =Ext.create('Balaee.model.qb.QbqnsModel',{
                    questionPaperNo:Paperno,
                    userId: UserId,
                });
        reviewQuestionStore.add(check);
        reviewQuestionStore.sync();  
}

所以它的工作是正确的。它以 json 格式发送数据为-

{"records":{"userId":"5","firstName":"abc","middleName":"","lastName":"","languageId":"","primaryEmail":"sdf@sdf.dfg","birthDate":"","password":"","securityQuestionId":"","securityQuestionAnswer":"","isMale":"","creationTime":"","ipAddress":"","confirmationCode":"","userStatusId":"","question":"","id":null}}

现在我想在 yii 控制器函数中捕获这些数据。我试过——

 $postData = json_decode(file_get_contents("php://input"), true); 
      $clientData = $postData['records']; 

并访问我正在使用 $clientData['firstName'] 的字段。但它不起作用。那么如何在 Yii 中捕获通过 Extjs 的 store sync() 方法发送的数据。

4

1 回答 1

1

使用标准 Yii Json 解码。它将为您创建数组

$data=  CJSON::decode(file_get_contents("php://input"));
于 2013-03-15T06:25:41.283 回答