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

前端 未结 6 1542
闹比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:54

    Extending Brian's answer.

    As you noted you can also check out $this->_request->getPost() and $this->_request->getQuery(). If you generalize on getParams(), it's sort of like using the $_REQUEST superglobal and I don't think that's acceptable in terms of security.

    Additional to Zend_Filter, you may also use simple PHP to cast the required.

    E.g.:

    $id = (int) $this->_request->getQuery('id');
    

    For other values, it gets more complicated, so make sure to e.g. quote in your DB queries (Zend_Db, see quoting identifiers, $db->quoteIdentifier()) and in views use $this->escape($var); to escape content.

提交回复
热议问题