How can I create functions that can be called in view (like in the index.ctp)?
I just wrote a function in one of my controllers:
public function getName($id) {
$name = $users
->find()
->where(['id' => $id ])
->first()
->username;
return $name;
}
The function should return the username according to the $id passed as a parameter. I just want to know how can I call a function from within my views. I'm getting this error:
"Error: Call to undefined function getName()"