开发者

Disable translator for Zend_Form_Element, but not it's validators

开发者 https://www.devze.com 2023-04-01 12:37 出处:网络
I have a Zend_Form_Element_Select object, and about 3k select options. When the customer asked me to look further into optimization possibilities, I did some debug tracing, and noticed, that there wer

I have a Zend_Form_Element_Select object, and about 3k select options. When the customer asked me to look further into optimization possibilities, I did some debug tracing, and noticed, that there were more than 3k calls to Zend_Form_Element_Multi->_translateValue and a little less to Zend_Form_Element_Multi->_translateOption . I found the option to set $elem->setDisableTranslator(true), which took care of these translations, for which I had no need. But the problem now is, that the error messages are no longer translated.

What I would like to know is, if there is a way to not translate values and options, but开发者_JAVA技巧 translate Validator messages?

I tried this:

foreach($operators->getValidators() as $val){
        $val->setDisableTranslator(false);
    }

but to no avail.


I don't see any option within the element classes so the simple solution would be extending the Zend_Form_Element_Select class with your own. Then you can override the _translateOptions method as follows

class My_Form_Element_Select extends Zend_Form_Element_Select {

    protected function _translateOption($option,$value) {
        // or add more logic here
        return false;
    }
}

Furthermore, you can set some additional logic and options for this scenario, i.e. turn on/off translation for options.

If you want to eliminate this calls all together you will have to override the getMultiOption() or getMultiOptions() which are calling _translateOption().

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号