Issues

ZF-3808: Zend_Filter_Null - converts zero to null

Issue Type: New Feature Created: 2008-07-30T09:50:38.000+0000 Last Updated: 2009-09-14T14:21:58.000+0000 Status: Resolved Fix version(s): - 1.10.0 (27/Jan/10)

Reporter: Michal Vrchota (techi) Assignee: Thomas Weidner (thomas) Tags: - Zend_Filter

Related issues: Attachments:

Description

In many situations when you work with database and selecting some value from combobox (Zend_Form_Element_Select) - you need transform the "0 => '-- no value --'" to null to be compatible with database reference integrity. Therefore there should be Zend_Filter_Null for such purpose. I suggest test value for empty() and return null

Comments

Posted by Thomas Weidner (thomas) on 2009-07-09T04:54:29.000+0000

Proposal added and waiting for recommendation from the devteam since 19.06.2009

Posted by Ramon Henrique Ornelas (ramon) on 2009-08-03T10:39:00.000+0000

I had this same problem, first built a filter Null.

But thought best and construct filter DefaultValue.

I think that this case.

code example simple in the class Filter_DefaultValue

__construct( $defaultValue = null );

filter($value) { return $defaultValue; }

Posted by Thomas Weidner (thomas) on 2009-08-03T11:17:40.000+0000

This does not work for the above described case. A "true" would in your case return "null" which is not wished behaviour.

Posted by Ramon Henrique Ornelas (ramon) on 2009-08-03T18:49:52.000+0000

sorry me, just gave a simple example.

I had the same problem in my Applications, this filter that built, solved my problem

protected $_defaultValue;

protected $_ruleApplyValue = array();

public function __construct( $defaultValue = null , $ruleApplyValue = null )
{
    $this->_defaultValue   = $defaultValue;
    $this->_ruleApplyValue = $ruleApplyValue;

    if( !is_array( $ruleApplyValue ) ){
        $this->_ruleApplyValue = array( $ruleApplyValue );
    }
}

public function filter($value)
{
    if( in_array( $value , $this->_ruleApplyValue ) ){
        return $this->_defaultValue;
    }

    return $value;
}

call

Zend_Filter::get( 'test' , 'DefaultValue' , array( null , 'test' ) )

Posted by Thomas Weidner (thomas) on 2009-09-14T14:21:41.000+0000

Closing as "Needs proposal". Proposal has been accepted New component within incubator waiting for acceptance to core since 14.09.2009.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts