Handling input with the Zend Framework (Post,get,etc)

前端 未结 6 1550
闹比i
闹比i 2021-02-01 05:04

im re-factoring php on zend code and all the code is full of $_GET[\"this\"] and $_POST[\"that\"]. I have always used the more phpish $this->_

6条回答
  •  执念已碎
    2021-02-01 05:43

    I usually use $this->_request->getParams(); to retrieve either the post or the URL parameters. Then I use the Zend_Filter_Input to do validation and filtering. The getParams() does not do validation.

    Using the Zend_Filter_Input you can do application level validation, using the Zend Validators (or you can write your own too). For example, you can make sure the 'months' field is a number:

    $data = $this->_request->getParams();
    
    $validators = array(
        'month'   => 'Digits',
    );
    
    $input = new Zend_Filter_Input($filters, $validators, $data);
    

提交回复
热议问题