我在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']的字段。但它不工作。所以如何捕获通过Extjs的store sync()方法发送的Yii中的数据。
答案 0 :(得分:1)
使用标准Yii Json decode.It将为您创建数组
$data= CJSON::decode(file_get_contents("php://input"));