gpt4 book ai didi

javascript - Yii + Backbone 获取数据

转载 作者:行者123 更新时间:2023-12-03 12:31:15 25 4
gpt4 key购买 nike

我需要从 Yii Controller 中的 Backbone 接收数据,但我不知道该怎么做。我需要将其放入我的 Controller 中,然后将其保存到数据库

主干代码

  var CallForm = Backbone.Model.extend({
defaults: {
projectname: null,
sll: null,
sspn: null,
z: null,
results: null,
step: null
},
url: './index.php',
validate: function(attr) {
if( !(attr.projectname && attr.sll && attr.sll) > 9 ) {
return "Error Occurred";
}
},

});

查看

        var callView = Backbone.View.extend({
el: '.callForm',
events: {
'click input.submit': 'getStatus'
},
getStatus: function(event){
//for each inputs function value
var NewProjectname = $('#projectname').val();
var NewCall = $('#call').val();
var NewSll = $('#sll').val();
var NewSspn = $('#sspn').val();
var NewZ = $('#z').val();
var NewResults = $('#results').val();
var NewStep = $('#step').val();
//new model parent CallForm with value's from inputs
var newrecord = new CallForm({
projectname: NewProjectname,
call: NewCall,
sll: NewSll,
sspn: NewSspn,
z: NewZ,
results: NewResults,
step: NewStep,
url: function() {
return '/callnew';
},
});
newrecord.save();
var json = newrecord.toJSON();
$('.test').html(JSON.stringify(json));
return false;
}
});
var callForm = new CallForm();
var callView = new callView({
model: callForm
});

Yii Controller 代码索引操作

public function actionIndex()
{
if(isset($_POST['index.php']))
{
echo 'You';

}
// renders the view file 'protected/views/site/index.php'
// using the default layout 'protected/views/layouts/main.php'
$this->render('index');
}

最佳答案

如果您使用 Yii >= 1.1.3:

$json = Yii::app()->request->getRawBody();
$yourData = CJSON::decode($json);

http://www.yiiframework.com/doc/api/1.1/CHttpRequest#getRawBody-detail

关于javascript - Yii + Backbone 获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23911893/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com