Zend_Validate_Db_RecordExists 针对 2 个字段 [英] Zend_Validate_Db_RecordExists against 2 fields

查看:23
本文介绍了Zend_Validate_Db_RecordExists 针对 2 个字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通常使用 Zend_Validate_Db_RecordExists 来更新或插入记录.这适用于一个要检查的字段.如果有两个字段要检查怎么办?

I usualy use Zend_Validate_Db_RecordExists to update or insert a record. This works fine with one field to check against. How to do it if you have two fields to check?

 $validator = new Zend_Validate_Db_RecordExists(
        array(
            'table' => $this->_name,
            'field' => 'id_sector,day_of_week'
            )
    );

    if ($validator->isValid($fields_values['id_sector'],$fields_values['day_of_week'])){
        //true
    }

我用数组和逗号分隔的列表尝试过,没有任何效果......欢迎任何帮助.问候安德里亚

I tried it with an array and comma separated list, nothing works... Any help is welcome. Regards Andrea

推荐答案

要做到这一点,您必须扩展 Zend_Validate_Db_RecordExists 类.

To do this you would have to extend the Zend_Validate_Db_RecordExists class.

它目前不知道如何检查是否存在多个字段.

It doesn't currently know how to check for the existence of more than one field.

您可以使用两个不同的验证器实例分别检查两个字段.除了扩展它之外,这是我现在能看到的唯一解决方法.

You could just use two different validator instances to check the two fields separately. This is the only work around that I can see right now besides extending it.

如果您选择扩展它,那么您必须找到某种方法将所有字段传递给构造函数(数组似乎是一个不错的选择),然后您必须深入研究创建sql查询.在此方法中,您必须遍历传入构造函数的字段数组.

If you choose to extend it then you'll have to find some way of passing in all the fields to the constructor ( array seems like a good choice ), and then you'll have to dig into the method that creates the sql query. In this method you'll have to loop over the array of fields that were passed in to the constructor.

这篇关于Zend_Validate_Db_RecordExists 针对 2 个字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆