[英]Problem saving ENUM field to MySQL using symfony1.4/Doctrine using jquery ajax call
I'm currently on a project that receives applications and the part I'm currently on has a grader that assigns a manual grade for the application. 我目前在一个接受申请的项目中,而我目前所从事的部分有一个为该应用分配手动评分的评分器。 The possible scores are enum values stored in a MySQL field. 可能的分数是存储在MySQL字段中的枚举值。 For whatever reason I cannot seem to get the value to actually be save to the database. 无论出于什么原因,我似乎都无法获得将值实际保存到数据库中的信息。
I have tried Doctrines Rawsql and I have tried the method below (that I would expect to work). 我已经尝试了Doctrines Rawsql,并且已经尝试了以下方法(希望可以使用)。 I have done testing to ensure that the values received on the server side to match the SQL enum field. 我已经做过测试,以确保在服务器端收到的值与SQL枚举字段匹配。 I've tried to include as much code as possible that I see as pertaining to the issue, but if there's more needed just let me know! 我尝试添加尽可能多的与该问题有关的代码,但是如果需要更多代码,请告诉我!
Function to update field in DB. 更新数据库中字段的功能。
public function executeSetLongAnswerGrade(sfWebRequest $request){
$application = $this->getRoute()->getObject();
if($request->isXmlHttpRequest()){
if($request->getParameter("methodCall") == "Passion"){
$application->setGradepassion($request->getParameter('value'));
return true;
}elseif($request->getParameter("methodCall") == "Grammer"){
$application->setGradegrammer($request->getParameter('value'));
}elseif($request->getParameter('methodCall') == "Thought"){
$application->setGradethought($request->getParameter('value'));
return true;
}
$application->save();
return true;
}
}
Route: 路线:
ajaxSetLongAnswerGrade:
url: /setLongAnswerGrade/:applicationId
class: sfDoctrineRoute
options: { model: Application, type: object}
param: { module: application, action: SetLongAnswerGrade }
requirements:
id: \d+
sf_method: [get]
Ajax Call: Ajax电话:
$(document).ready(function(){
$('#passionMSG').hide();
$('#grammerMSG').hide();
$('#thoughtMSG').hide();
$('.passionSuccess').hide();$('.passionError').hide();
$('.grammerSuccess').hide();$('.grammerError').hide();
$('.thoughtSuccess').hide();$('.thoughtError').hide();
$('#passion').change(function()
{
$('#passion').attr('disabled', true);
$('.passionSuccess').hide();
$('#passionMSG').slideDown(200);
$('.passionError').hide();
$.ajax({
url: '<?php echo url_for2('ajaxSetLongAnswerGrade', $application) ?>',
data: { methodCall: "Passion",
value: this.value} ,
success: function(data) {
$('#passion').attr('disabled', false);
$('#passionMSG').slideUp(1500)
$('.passionSuccess').delay(1300).slideDown(2000);
},
error: function(){
$('#passion').attr('disabled', false);
$('#passionMSG').slideUp(1500)
$('.passionError').delay(1300).slideDown(2000);
}
});
});});
When you use return
in ana action it sends the response... you have return
in each of your conditions but you arent calling $application->save();
当您在ana操作中使用return
,它会发送响应...您在每种情况下都已return
,但是您不能调用$application->save();
;。 first. 第一。
Elimintate the returns, or call save before each return: 取消退货,或在每次退货前调用save:
public function executeSetLongAnswerGrade(sfWebRequest $request){
$application = $this->getRoute()->getObject();
if($request->isXmlHttpRequest()){
if($request->getParameter("methodCall") == "Passion"){
$application->setGradepassion($request->getParameter('value'));
}elseif($request->getParameter("methodCall") == "Grammer"){
$application->setGradegrammer($request->getParameter('value'));
}elseif($request->getParameter('methodCall') == "Thought"){
$application->setGradethought($request->getParameter('value'));
}
$application->save();
return true;
}
}
I Would also probably revise this logic to: 我可能还会将此逻辑修改为:
public function executeSetLongAnswerGrade(sfWebRequest $request)
{
$application = $this->getRoute()->getObject();
if($request->isXmlHttpRequest())
{
$call = $request->getParameter('methodCall');
$value = $request->getParameter('value');
switch($call)
{
case 'Passion':
$application->setGradepassion($value);
break;
case 'Grammer':
$application->setGradegrammer($value);
break;
case 'Thought':
$application->setGradethought($value);
break;
default:
throw new Exception('Invalid methodCall.');
}
$application->save();
return sfView::NONE;
}
}
This ended up being in my routing.yml file. 最终在我的routing.yml文件中。 The lack of method: find
in options: { model: Application, type: object}
is what was causing the error. 缺少method: find
在options: { model: Application, type: object}
method: find
options: { model: Application, type: object}
是引起错误的原因。 A save was occuring, but not on the record I was wanting (I thought this was implicit but it instantly started working after I added this). 正在进行保存,但是没有保存在我想要的记录上(我以为这是隐式的,但添加后立即开始工作)。 final code... 最终代码...
public function executeSetLongAnswerGrade(sfWebRequest $request){
$application = $this->getRoute()->getObject();
if($request->isXmlHttpRequest()){
$application->{$request->getParameter('value')}($request->getParameter('value'));
$application->save();
return sfView::NONE;
}else{
return false;
}
and the ajax.... 和ajax。
$('#passion').attr('disabled', true);
$('.passionSuccess').hide();
$('#passionMSG').slideDown(200);
$('.passionError').hide();
$.ajax({
url: '<?php echo url_for2('ajaxSetLongAnswerGrade', $application) ?>',
data: { methodCall: "setGradepassion",
value: this.value} ,
success: function(data) {
$('#passion').attr('disabled', false);
$('#passionMSG').slideUp(1500)
$('.passionSuccess').delay(1300).slideDown(2000);
},
error: function(){
$('#passion').attr('disabled', false);
$('#passionMSG').slideUp(1500)
$('.passionError').delay(1300).slideDown(2000);
}
});
I do appreciate the guidance! 我非常感谢指导! I was raised Java and still getting used to symfony/php. 我从小就受过Java训练,仍然习惯了symfony / php。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.