-1

I don't understand this user defined function:

function get_or_post($var, $dfvalue = "") {
    $CI = & get_instance();
    $value = $dfvalue;
    if (!empty($var)) {
        if ($CI->input->get($var) != FALSE) {
            $value = $CI->input->get($var);
        } else if ($CI->input->post($var) != FALSE) {
            $value = $CI->input->post($var);
        }
    }
    return $value;
}
Vickel
  • 7,879
  • 6
  • 35
  • 56
ML680
  • 99
  • 1
  • 1
  • 10
  • Detects HTTP method, see: http://stackoverflow.com/questions/11189969/how-to-detect-http-method-in-codeigniter – Sébastien Vercammen Mar 03 '16 at 11:32
  • it just looks whether there is a value in the superglobal _GET oder _POST array and returns it or returns a default value which is the 2nd parameter – Atural Mar 03 '16 at 11:33

2 Answers2

1

This function checks wheather the $var data is from post or get method using codeigniter's instance.

Ananta Prasad
  • 3,655
  • 3
  • 23
  • 35
1

Assign the CodeIgniter object to a variable. Then assign NULL value for $value. Inside if condition set the value of $value. If the value is coming through get method then set the value by $CI->input->get($var) and the value is coming through post method then set the value by $CI->input->post($var) . At last return $value.

Sharmistha Das
  • 175
  • 1
  • 9