2024-04-24 13:20:52 +07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Controllers;
|
|
|
|
|
|
|
|
|
|
use App\Models\ProductServiceModel;
|
|
|
|
|
use CodeIgniter\Controller;
|
|
|
|
|
|
|
|
|
|
class ProductService extends Controller {
|
|
|
|
|
|
|
|
|
|
public function index() {
|
|
|
|
|
$db = \Config\Database::connect();
|
|
|
|
|
$sql = "SELECT * FROM productservice";
|
|
|
|
|
$query = $db->query($sql);
|
|
|
|
|
$results = $query->getResultArray();
|
|
|
|
|
$data['productservice'] = $results;
|
|
|
|
|
return view('productservice_index', $data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function create() {
|
|
|
|
|
$db = \Config\Database::connect();
|
|
|
|
|
$data = array();
|
2025-08-18 15:33:39 +07:00
|
|
|
if ($this->request->getMethod() === 'POST') {
|
2024-04-24 13:20:52 +07:00
|
|
|
$rules = [
|
|
|
|
|
'productservicetext' => 'required'
|
|
|
|
|
];
|
|
|
|
|
$data['new_value'] = [
|
|
|
|
|
'productservicetext' => $this->request->getVar('productservicetext')
|
|
|
|
|
];
|
|
|
|
|
if($this->validate($rules)){
|
|
|
|
|
$productServiceModel = new ProductServiceModel();
|
|
|
|
|
$productServiceModel->set('createdate', 'NOW()', FALSE);
|
|
|
|
|
$productServiceModel->insert($data['new_value']);
|
|
|
|
|
return view('form_success');
|
|
|
|
|
} else {
|
|
|
|
|
$data['validation'] = $this->validator;
|
|
|
|
|
return view('productservice_create',$data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return view('productservice_create', $data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function edit($productserviceid = null) {
|
|
|
|
|
$db = \Config\Database::connect();
|
|
|
|
|
$sql = "SELECT * FROM productservice WHERE productserviceid='$productserviceid'";
|
|
|
|
|
$query = $db->query($sql);
|
|
|
|
|
$results = $query->getResultArray();
|
|
|
|
|
$data['productservice'] = $results;
|
2025-08-18 15:33:39 +07:00
|
|
|
if ($this->request->getMethod() === 'POST') {
|
2024-04-24 13:20:52 +07:00
|
|
|
$rules = [
|
|
|
|
|
'productservicetext' => 'required'
|
|
|
|
|
];
|
|
|
|
|
$data['new_value'] = [
|
|
|
|
|
'productservicetext' => $this->request->getVar('productservicetext')
|
|
|
|
|
];
|
|
|
|
|
if($this->validate($rules)){
|
|
|
|
|
$productServiceModel = new ProductServiceModel();
|
|
|
|
|
$productServiceModel->update($productserviceid, $data['new_value']);
|
|
|
|
|
return view('form_success');
|
|
|
|
|
} else {
|
|
|
|
|
$data['validation'] = $this->validator;
|
|
|
|
|
return view('productservice_edit',$data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return view('productservice_edit', $data);
|
|
|
|
|
}
|
|
|
|
|
}
|