i am just playing with slim framework and its amazing!.here i am developing this search function in my API my question is if by any chance i send an empty string the result is 404 i tried to manage this inside function,but it fails.As i am new to this can anyone suggest the best approach?
$app->get('/search/:str', 'authenticate', function($searchq) {
global $user_id;
$car_manager_upload_url = 'http://xxx.com/images/';
$car_manager_upload_dir = '/home/public_html/images/';
$response = array();
$db = new DbHandler();
// fetch task
if($searchq!=NULL || $search!=""){
$result = $db->getVehicles($searchq);
if ($result != NULL) {
$response["error"] = false;
$response["cars"] = array();
// looping through result and preparing cars array
while ($task = $result->fetch_assoc()) {
$tmp = array();
$tmp["carid"] = $task["vehicleId"];
$tmp["reg_number"] = $task["first_name"];
$tmp["slug"] = $task["slug"];
$carOptions = unserialize($task["options"]);
$carName = basename($carOptions["image"]["meta"]["original"]["url"]);
$path = (file_exists($car_manager_upload_dir.$tmp["slug"].'/'.$carName)?$car_manager_upload_url.$tmp["slug"].'/'.$carName:'http://xxx.com/images/nophoto-200x200.jpg');
$tmp["image"]=$path;
$tmp["brand"] = $task["middle_name"];
$tmp["model"] = $task["last_name"];
$tmp["insurance_policy_number"] = $task["honorific_suffix"];
$tmp["createdAt"] = $task["date_added"];
$tmp["assignedTo"]=$task["display_name"];
$tmp["issuedAt"]=$task["issuedDate"].",".$task["issuedTime"];
$tmp["returnedAt"]=(($task["returnedDate"]=='0000-00-00')?'notReturned':$task["returnedDate"].",".$task["returnedTime"]);
$tmp["availability"]=(($task["returnedDate"]!='0000-00-00')?true:false);
array_push($response["cars"], $tmp);
}
echoRespnse(200, $response);
} else {
$response["error"] = true;
$response["message"] = "We couldn't find any similerities";
echoRespnse(404, $response);
}
}
else{
$response["error"] = true;
$response["message"] = "Empty String";
echoRespnse(404, $response);
}
});