54 lines
1.6 KiB
PHP
54 lines
1.6 KiB
PHP
<?php
|
|
namespace App\Controllers;
|
|
|
|
use CodeIgniter\API\ResponseTrait;
|
|
use CodeIgniter\Controller;
|
|
|
|
class Country extends Controller {
|
|
use ResponseTrait;
|
|
|
|
public function __construct() {
|
|
$this->db = \Config\Database::connect();
|
|
}
|
|
|
|
public function index() {
|
|
try {
|
|
|
|
$Country = $this->request->getVar('Country');
|
|
|
|
if ($Country != null) {
|
|
$filterQuery = " WHERE Country LIKE '%$Country%'";
|
|
} else {
|
|
$filterQuery = "";
|
|
}
|
|
|
|
$sql = "SELECT IntCountryID, CountryID, Country FROM country $filterQuery";
|
|
$data = $this->db->query($sql)->getResultArray();
|
|
|
|
return $this->respond([
|
|
'status' => 'success',
|
|
'message'=> "Country fetched successfully",
|
|
'data' => $data,
|
|
], 200);
|
|
} catch (\Exception $e) {
|
|
return $this->failServerError('Something went wrong '.$e->getMessage());
|
|
}
|
|
}
|
|
|
|
public function show($IntCountryID = null) {
|
|
try {
|
|
|
|
$sql = "SELECT IntCountryID, CountryID, Country FROM country WHERE IntCountryID = $IntCountryID";
|
|
$data = $this->db->query($sql)->getResultArray();
|
|
|
|
return $this->respond([
|
|
'status' => 'success',
|
|
'message'=> "Country with IntCountryID $IntCountryID fetched successfully",
|
|
'data' => $data,
|
|
], 200);
|
|
} catch (\Exception $e) {
|
|
return $this->failServerError('Something went wrong '.$e->getMessage());
|
|
}
|
|
}
|
|
|
|
} |