first commit
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
|
||||
class Credit_card_benefits extends Admin_Controller
|
||||
{
|
||||
|
||||
public $viewData = array();
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
// Load model
|
||||
$this->load->model('credit_card_benefit_model');
|
||||
}
|
||||
|
||||
private function getFormValue()
|
||||
{
|
||||
return [
|
||||
'benefit_id' => $this->input->post('benefit_id[]') ?? [],
|
||||
'benefit' => $this->input->post('benefit[]') ?? [],
|
||||
'expired_date' => $this->input->post('expired_date[]') ?? [],
|
||||
];
|
||||
}
|
||||
|
||||
public function update() {
|
||||
$this->load->helper(array('form', 'url'));
|
||||
$this->load->library('form_validation');
|
||||
|
||||
$params = $this->getFormValue();
|
||||
|
||||
$this->form_validation->set_data($params);
|
||||
$this->setFormRuleUpdate();
|
||||
if ($this->form_validation->run() == false) {
|
||||
// Rerender filter if validate fail
|
||||
echo json_encode([
|
||||
'code' => '500',
|
||||
'message' => validation_errors()
|
||||
]);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$this->credit_card_benefit_model->update($params);
|
||||
echo json_encode([
|
||||
'code' => '200',
|
||||
'message' => 'Updated Successful'
|
||||
]);
|
||||
}
|
||||
|
||||
public function setFormRuleUpdate()
|
||||
{
|
||||
$this->form_validation->set_rules('benefit_id[]', 'ID', 'required');
|
||||
$this->form_validation->set_rules('benefit[]', 'Benefit', 'required|max_length[256]');
|
||||
$this->form_validation->set_rules('expired_date[]', 'Expired Date', 'regex_match[/\d{4}-\d{2}-\d{2}/]');
|
||||
}
|
||||
|
||||
public function validateForm(&$params)
|
||||
{
|
||||
if ($this->form_validation->run() == false) {
|
||||
// Rerender filter if validate fail
|
||||
$this->viewData['msg'] = validation_errors();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user