My Yii应用程序保存和规则错误
我改变了很多密码 这是我的控制器中的代码:My Yii应用程序保存和规则错误,yii,save,rule,Yii,Save,Rule,我改变了很多密码 这是我的控制器中的代码: 公共功能actionRequestTV(){ } 规则如下: public function rules() { // NOTE: you should only define rules for those attributes that // will receive user inputs. return array( array('BPID, SK', 'num
公共功能actionRequestTV(){
}
规则如下:
public function rules() {
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('BPID, SK', 'numerical', 'integerOnly' => true),
array('BPMOBILE', 'numerical'),
array('TVID, TVPASS', 'length', 'max' => 50),
array('PROBLEM', 'length', 'max' => 250),
array('BPCP, BPMOBILE, BPEMAIL', 'length', 'max' => 255),
array('SK', 'ceksk'),
array('BPEMAIL', 'email'),
array('PSNO', 'cekPSNO'),
// array('SK, PROBLEM, TVID, TVPASS', 'required', 'on' => 'step2'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('REQTVID, BPID, TVID, TVPASS, PROBLEM, SK, BPCP, BPMOBILE, BPEMAIL, PSNO', 'safe', 'on' => 'search'),
);
}
在将我的代码从更改为更简单的代码(如上面的代码)之后,它已经能够保存这些值。但是,有些规则不起作用,比如塞克斯克规则。这是ceksk的代码:
public function ceksk() {
if($this->SK){
if (!$this->SK == 1) {
$this->addError('SK', 'Maaf, anda harus mencentang persetujuan syarat & ketentuan sebelum melanjutkan');
return false;
}
}
}
更新
我的ceksk规则已经起作用了。但我决定改用JQuery:
<?php
Yii::app()->clientScript->registerScript('JQuery', "
$('#kirim').click(function() {
if ($('#SK').attr('checked')) {
return true;
}else{
alert('Anda belum mencentang Syarat & Ketentuan');
return false;
}
});
");
?>
请,我们非常感谢你的帮助。谢谢:)试试这个:
public function ceksk($attribute) {
if (!$this->$attribute == 1)
$this->addError($attribute, 'Maaf, anda harus mencentang persetujuan syarat & ketentuan sebelum melanjutkan');
}
资料来源:
如果(!$this->SK==1)
无法产生您想要的结果
尝试使用if($this->SK!=1)
看
来自的否定
出现在比较运算符之前,这意味着您正在有效地执行(!$this->SK)==1)
这将导致代码块永远不会执行,因为如果存在
$This->SK
,并且可以将type juggled设置为true,那么它的否定将导致false
值,与1
(真值)相比,该值永远不会为true。然而,如果$this->SK
为空或键入变为false,则以后将永远不会执行不正确的比较,因此您的验证将永远不会报告失败。hi@whale\u steward我已经尝试过了,但仍然不起作用。仅供参考,SK是一个复选框。无论如何,谢谢:)您的解决方案中有一个输入错误。你错过了一个$signif(!$this->$attribute==1)
而不是if(!$this->attribute==1)
。你好@Willem Renzema,谢谢你的回复。我试过你的建议,但还是不行。因此,我决定改用JQuery:cekPSNO:public function cekPSNO(){if($this->PSNO){$PSNO=Ps::model()->findByAttributes(array('PSNO'=>$this->PSNO));//检查cdsn ada或tidak if($PSNO==null){$this->addError('PSNO','Nomor PS tidak ditemukan,silahkan periksa Nomor PS anda!');返回false;}否则{if(date('Y-m-d')>$PSNO->TGLBERAKHIR){$this->addError('PSNO','Premium Support sudah expired!');返回false;}
public function cekPSNO() {
if ($this->PSNO) {
$psno = Ps::model()->findByAttributes(array('PSNO' => $this->PSNO));
//check cdsn ada atau tidak
if ($psno === null) {
$this->addError('PSNO', 'Nomor PS tidak ditemukan, silahkan periksa Nomor PS anda !');
return false;
} else {
if (date('Y-m-d') > $psno->TGLBERAKHIR) {
$this->addError('PSNO', 'Premium Support sudah expired !');
return false;
}
}
}
}
public function ceksk($attribute) {
if (!$this->$attribute == 1)
$this->addError($attribute, 'Maaf, anda harus mencentang persetujuan syarat & ketentuan sebelum melanjutkan');
}