Search code examples
codeignitergrocery-crud

Update data using add action


I'm use Grocery CRUD. I create custom button using add_action.

The button for change data to 0. So, after click the button database update column to 0.

Controller:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');


class Attendance extends Admin_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->library('form_builder');
    }

public function attendance($visitor_id)
    {
        $attendance_status = array(
            'attendance_status' => 0
        );

        $update = $this->Attendace_model->update_attendance_status($visitor_id,$attendance_status);

       if($update)
       {
           $this->load->view('Attendance');
       }
       else
       {
           alert("error");
       }
   }
}

Model :

<?php

class Attendance_model extends MY_Model {

    function __construct()
    {
        parent::__construct();
    }

    function update_attendance_status($visitor_id,$attendance_status)
    {
        $this->db->where('id', $visitor_id);
        $this->db->update('invitation_codes', $attendance_status);
    }
}

What code to use in function for update the data to 0/


Solution

  • Controller:

       public function attendance($visitor_id)
       {
               $attendance_status = array(
               'attendance_status' => 0
               );
    
           $update = $this->YOUR_MODEL_NAME- >update_attendance_status($visitor_id,$attendance_status);
    
           if($update)
          {
             return true;
          }
          else
          {
             return false;
          }
       }
    

    Model :

      public function update_attendance_status($visitor_id,$attendance_status)
     {
      $this->db->where('id', $visitor_id);
      $this->db->update('invitation_codes', $attendance_status);
     }