I have a database with some “filters”; i.e. method calls and want to be able to call them dynamically dependent on what the user has input.
Code Igniter does not seem to like this however, any ideas?
It outputs:
In GetEmailCountfilter_male_count():
<h4>A PHP Error was encountered</h4>
<p>Severity: Notice</p>
<p>Message: Undefined property: Targeted_Email::$filter_male_count()</p>
<p>Filename: core/Model.php</p>
<p>Line Number: 51</p>
{"emailCount":null}
Code:
public function getEmailCount($filter){
echo 'In GetEmailCount';
$result = array();
$query = $this->db->get('base_targeted_email_filters');
foreach ($query->result() as $row){
if($filter == $row->name){
$test = $row->filterCountFunction . "()";
echo $test;
$result['emailCount'] = $this->{$test};
}
return $result
}
The foreach loop should be like this: