I am trying to get json response in my app, and for that I've created this action in controller class
public function signupAction()
{
$this->view->disable();
//Create a response instance
$response = new \Phalcon\Http\Response();
$robots = Users::find(array(
"uname = 'viralj'",
));
$data = array();
if(!empty($robots)){
foreach ($robots as $robot) {
$data[] = array(
'error' => 'false',
'userfound' => 'true',
'id' => $robot->id,
'fname' => $robot->fname,
'lname' => $robot->lname,
'email' => $robot->email,
'pass' => $robot->password,
'reg' => $robot->regdatetime
);
}
}else{
$data[] = array("error" => "true", "userfound" => "false");
}
echo json_encode($data);
}
so when I try to access the required page, I get details from my database because I have a user with username of "viralj". But when I try to check with false details, like "abc" username which I don't have in my database, insted of getting this ("error" => "true", "userfound" => "false") in json format, i am getting brackets lke this [] in my webpage. so can anyone tell me how can i figure this out? And also if I want to check that if someone is login with username or email how can i check this in one query? What codes should I write in this with condition of username or email
$robots = Users::find(array(
"uname = 'viralj'",
));
Please let me know. Thank you for your time.