43 lines
1.3 KiB
PHP
43 lines
1.3 KiB
PHP
<?php
|
|
namespace App\Controllers;
|
|
|
|
use CodeIgniter\API\ResponseTrait;
|
|
use CodeIgniter\Controller;
|
|
|
|
class Religion extends Controller {
|
|
use ResponseTrait;
|
|
|
|
public function __construct() {
|
|
$this->db = \Config\Database::connect();
|
|
}
|
|
|
|
public function index() {
|
|
try {
|
|
$sql = "SELECT * FROM religion";
|
|
$data = $this->db->query($sql)->getResultArray();
|
|
|
|
return $this->respond([
|
|
'status' => 'success',
|
|
'message'=> "Religion fetched successfully",
|
|
'data' => $data,
|
|
], 200);
|
|
} catch (\Exception $e) {
|
|
return $this->failServerError('Something went wrong '. $e->getMessage());
|
|
}
|
|
}
|
|
|
|
public function show($ReligionID = null) {
|
|
try {
|
|
$sql = "SELECT * FROM religion WHERE ReligionID = $ReligionID";
|
|
$data = $this->db->query($sql)->getResultArray();
|
|
|
|
return $this->respond([
|
|
'status' => 'success',
|
|
'message'=> "Religion with ReligionID $ReligionID fetched successfully",
|
|
'data' => $data,
|
|
], 200);
|
|
} catch (\Exception $e) {
|
|
return $this->failServerError('Something went wrong '.$e->getMessage());
|
|
}
|
|
}
|
|
} |