clqms-be/app/Controllers/AreaGeo.php
2025-12-02 13:19:42 +07:00

47 lines
1.7 KiB
PHP

<?php
namespace App\Controllers;
use CodeIgniter\API\ResponseTrait;
use App\Controllers\BaseController;
use App\Models\AreaGeoModel;
class AreaGeo extends BaseController {
use ResponseTrait;
protected $model;
public function __construct() {
$this->model = new AreaGeoModel();
}
public function index() {
try {
$filters = [
'AreaGeoID' => $this->request->getVar('AreaGeoID') ?? null,
'AreaName' => $this->request->getVar('AreaName') ?? null
];
$rows = $this->model->getAreaGeos( $filters );
if(empty($rows)){return $this->respond(['status'=>'success', 'message'=>"no data found.", 'data'=>$rows], 200);}
return $this->respond(['status'=>'success', 'message'=>"data fetched successfully", 'data'=>$rows], 200);
} catch (\Exception $e) {
return $this->respond([ 'status' => 'error', 'message' => $e->getMessage() ], 200);
}
}
public function getProvinces() {
$rows = $this->model->getProvinces();
if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "data not found", 'data' => '' ], 200); }
return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200);
}
public function getCities() {
$filter = [ 'Parent' => $this->request->getVar('Parent') ?? null ];
$rows = $this->model->getCities($filter);
if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "data not found", 'data' => [] ], 200); }
return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200);
}
}