I am writing a custom function in a Member controller. The purpose of the function is this:-
- First it checks if an id exists in the
memberstable. - If it doesn't exist then it returns 0;
- if it exists, then it checks whether the isActive status is 0 or 1;
- if it's 0, then it returns 0, else 1;
Now, I am writing the function as these:-
public function memberExist($id)
{
$query = "SELECT Member.id FROM members AS Member WHERE Member.id = $id AND Member.isActive = 1";
// Here I want to write something like:
// if($this->query($query)->num_rows()>0) return 1; else return 0;
}
However, the problem is, I don't now how to get number of rows from query builder(sorry if the name is not exact, I am new to cakephp).
$this->query($query) returns array.
In controller, we can use following method to get number of rows,
$userdata = $this->Member->find('count',array('conditions'=>array('Member.id'=>$id, 'Member.isActive'=>1)));
But how to apply count procedure in the Model?
$this->Memberis a model object, think about that.