我在会员表格中添加了两个字段,但无法从数据库中获取值,但是在数据库中保存了我做错了什么?这里我的代码请检查
我在表ohrm_membership中添加了两个字段,即:practicetype,praticetypeother
membershipSuccess.js
$(document).ready(function() {
$('#btnSave').click(function() {
$('#frmMembership').submit();
});
$('#membership').hide();
$('#btnAdd').click(function() {
$('#membership').show();
$('.top').hide();
$('#membership_name').val('');
$('#membership_praticetypeother').val('');
$('#membership_membershipId').val('');
$('#membershipHeading').html(lang_addMembership);
$(".messageBalloon_success").remove();
});
$('#btnCancel').click(function() {
$('#membership').hide();
$('.top').show();
$('#btnDelete').show();
validator.resetForm();
});
$('a[href="javascript:"]').click(function(){
var row = $(this).closest("tr");
var statId = row.find('input').val();
var url = membershipInfoUrl+statId;
$('#membershipHeading').html(lang_editMembership);
getMembershipInfo(url);
});
$('#btnDelete').attr('disabled', 'disabled');
$("#ohrmList_chkSelectAll").click(function() {
if($(":checkbox").length == 1) {
$('#btnDelete').attr('disabled','disabled');
}
else {
if($("#ohrmList_chkSelectAll").is(':checked')) {
$('#btnDelete').removeAttr('disabled');
} else {
$('#btnDelete').attr('disabled','disabled');
}
}
});
$(':checkbox[name*="chkSelectRow[]"]').click(function() {
if($(':checkbox[name*="chkSelectRow[]"]').is(':checked')) {
$('#btnDelete').removeAttr('disabled');
} else {
$('#btnDelete').attr('disabled','disabled');
}
});
$('#btnDelete').click(function(){
$('#frmList_ohrmListComponent').submit(function(){
$('#deleteConfirmation').dialog('open');
return false;
});
});
$('#frmList_ohrmListComponent').attr('name','frmList_ohrmListComponent');
$('#dialogDeleteBtn').click(function() {
document.frmList_ohrmListComponent.submit();
});
$('#dialogCancelBtn').click(function() {
$("#deleteConfirmation").dialog("close");
});
$.validator.addMethod("uniqueName", function(value, element, params) {
var temp = true;
var currentStatus;
var id = $('#membership_membershipId').val();
var memCount = membershipList.length;
for (var j=0; j < memCount; j++) {
if(id == membershipList[j].id){
currentStatus = j;
}
}
var i;
var name = $.trim($('#membership_name').val()).toLowerCase();
var pratice = $.trim($('#membership_practice').val()).toLowerCase();
var praticetypeother =$.trim($('#membership_praticetypeother').val()).toLowerCase();
for (i=0; i < memCount; i++) {
arrayName = membershipList[i].name.toLowerCase();
if (name == arrayName) {
temp = false
break;
}
arrayPratice = membershipList[i].pratice.toLowerCase();
if (pratice == arrayPratice) {
temp = false
break;
}
arrayPraticetypeother = membershipList[i].praticetypeother.toLowerCase();
if (praticetypeother == arrayPraticetypeother) {
temp = false
break;
}
}
if(currentStatus != null){
if(name == membershipList[currentStatus].name.toLowerCase()){
temp = true;
}
if(pratice == membershipList[currentStatus].pratice.toLowerCase()){
temp = true;
}
}
return temp;
});
var validator = $("#frmMembership").validate({
rules: {
'membership[name]' : {
required:true,
maxlength: 50,
uniqueName: true
}
},
messages: {
'membership[name]' : {
required: lang_NameRequired,
maxlength: lang_exceed50Charactors,
uniqueName: lang_uniqueName
}
}
});
});
function getMembershipInfo(url){
$.getJSON(url, function(data) {
$('#membership_membershipId').val(data.id);
$('#membership_name').val(data.name);
$('#membership_practice').val(data.practice);
$('#membership_praticetypeother').val(data.praticetypeother);
$('#membership').show();
$(".messageBalloon_success").remove();
$('.top').hide();
});
}
MembershipForm .php class MembershipForm扩展了BaseForm {
private $membershipService;
public function getMembershipService() {
if (is_null($this->membershipService)) {
$this->membershipService = new MembershipService();
$this->membershipService->setMembershipDao(new MembershipDao());
}
return $this->membershipService;
}
public function configure() {
$this->setWidgets(array(
'membershipId' => new sfWidgetFormInputHidden(),
'name' => new sfWidgetFormInputText(),
'praticetypeother' => new sfWidgetFormInputText(),
'practice' => new sfWidgetFormSelect(array(
"choices" => array('Fin' => 'Fin','HRM' => 'HRM','SCM'=>'SCM','CRM'=>'CRM','Others'=>'Others')
)),
));
$this->setValidators(array(
'membershipId' => new sfValidatorNumber(array('required' => false)),
'name' => new sfValidatorString(array('required' => true, 'max_length' => 50)),
'practice' => new sfValidatorString(array('required' => true, 'max_length' => 100)),
'praticetypeother' => new sfValidatorString(array('required' => false, 'max_length' => 100)),
));
$membershipList = $this->getMembershipService()->getMembershipList();
foreach ($membershipList as $membership) {
$list[] = array('id' => $membership->getId(),
'name' => $membership->getName(),
'practice'=>$membership->getPracticetype(),
'praticetypeother'=>$membership->getPraticetypeother());
}
$this->widgetSchema->setNameFormat('membership[%s]');
}
public function save() {
$membershipId = $this->getValue('membershipId');
if (!empty($membershipId)) {
$membership = $this->getMembershipService()->getMembershipById($membershipId);
} else {
$membership = new Membership();
}
$membership->setName($this->getValue('name'));
$membership->setPracticetype($this->getValue('practice'));
$membership->setPraticetypeother($this->getValue('praticetypeother'));
$membership->save();
}
public function getMembershipListAsJson() {
$list = array();
$membershipList = $this->getMembershipService()->getMembershipList();
foreach ($membershipList as $membership) {
$list[] = array('id' => $membership->getId(),
'name' => $membership->getName(),
'practice'=>$membership->getPracticetype(),
'praticetypeother'=>$membership->getPraticetypeother());
}
return json_encode($list);
}
}