I use Codeigniter as my PHP framework, and in one of my controllers, I want to include a Codeingiter method within a function I created myself. The CodeIgniter method that I want to include in my function is "$this->db->escape($var);", which is an escaping query for Codeigniter. My PHP code is the following:
foreach ($array as $item)
{
$name = $item["name"];
$name = processvar($name);
}
function processvar($var) {
$var = $this->db->escape($var);
return $var;
}
However, the code above produces the following error message:
Fatal error: Using $this when not in object context in [folder path]/index.php on line #
Please advise how I can include the "$this->db->escape()" method in my own custom function.
function processvar($var) {
$CI =& get_instance();
$var = $CI->db->escape($var);
return $var;
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments