我正在使用下面链接中详述的Zend_Validate_Db_NoRecordExists
来检查记录是否存在,然后再插入。
我对基本代码没有任何问题并且工作正常,我接下来需要做的是添加一个WHERE子句来排除字段recordDelete = 1的记录。
Zebd_Validate_Db_NoRecordExists
以下是我正在使用此代码的代码片段:
$validator = new Zend_Validate_Db_NoRecordExists($options);
$form->getElement('productSTOCKCODE')->addValidator($validator);
由于
答案 0 :(得分:4)
$validate = new Zend_Validate_Db_RecordExists (array (
'table' => 'orders',
'field' => 'id',
'exclude' => 'recordDelete = 1'
));
$result = $validate->isValid ('000489FS1qT81XR4GWuV');
答案 1 :(得分:1)
您可以尝试创建自己的版本并设置$_exclude
成员变量。
(未测试的)
class My_Validate_Db_NoRecordExists
extends Zend_Validate_Db_NoRecordExists // notice what were extending here
{
protected $_exclude = array(
'field' => 'recordDelete',
'value' => 1
);
}
或者你可以将$exclude
param传递给构造函数,无论你在哪里使用它:
$options = array(
'table' => $yourTable,
'field' => $yourField,
'exclude' => array( // <- set exclude here
'field' => 'recordDelete',
'value' => 1
)
);
$dbValidator = new Zend_Validate_Db_NoRecordExists($options);