문제

I am working with Zend Form, and on the edit i want the values to be like ucfirst(values) ;. I found filters 'filters' => array('StringToUpper') but they work on the hole input. Any idea ? Thanks

도움이 되었습니까?

해결책

No such filter exists but it would be trivial to create your own:

 class My_Filter_StringUCFirst implements Zend_Filter_Interface {
     public function filter($value){
         return ucfirst($value);
     }
 }

다른 팁

Perhaps it's time for a custom filter.

Something like:

class UcFirstFilter implements Zend_Filter_Interface
{
    public function filter($value)
    {
        // perform some transformation upon $value to arrive on $valueFiltered
        $valueFiltered=ucfirst($value);
        return $valueFiltered;
    }
}
$filterChain = new Zend_Filter();
$filterChain->addFilter(new UcFirstFilter());

I found this solution , i've changed my populate function :

public function populate($data) {
 ....

    foreach ($data as $field => $value) {

            if (in_array($field, array("fields you want in ucfirst")) )
                $value=  ucfirst ($value);

            $this->{$field}->setValue($value);
      }

    return $this;
}

Hope this will help.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top