Bedhoel

controllers/SkillController.php

Nov 5th, 2020
2,085
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.61 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. class SkillController extends CI_Controller {
  4.     protected $data;
  5.  
  6.     public function __construct()
  7.     {
  8.         parent::__construct();
  9.         $this->load->model('Skill');
  10.     }
  11.  
  12.     public function RestData()  
  13.     {  
  14.         $list = $this->Skill->get_datatables();   //Using CI_Model
  15.         $data = array();
  16.         $no = @$_POST['start'];
  17.         foreach ($list as $res) {
  18.  
  19.              $no++;
  20.             //Define Button
  21.             $allButton    = "";
  22.             $buttonEdit   = "<button type='button' onclick='get_data(\"".$res->id_skill."\")'>Edit</button>";
  23.             $buttonDelete = "<button type='button' onclick='delete_data(\"".$res->id_skill."\")'>Delete</button>";
  24.             $allButton .= $buttonEdit;
  25.             $allButton .= $buttonDelete;
  26.  
  27.             $row = array();
  28.             $row[] = $allButton;
  29.             $row[] = $res->nama_keahlian;
  30.             $data[] = $row;
  31.         }
  32.  
  33.         $output = array(
  34.                     "draw" => @$_POST['draw'],
  35.                     "recordsTotal" => $this->Keahlian->count_all(),
  36.                     "recordsFiltered" => $this->Keahlian->count_filtered(),
  37.                     "data" => $data,
  38.         );
  39.         // output to json format
  40.         echo json_encode($output);
  41.     }
  42.     public function DetailData()  
  43.         $req  = $this->input->post();
  44.         $id   =  $req['id_parameter'];
  45.         $data = Skill::where('id_skill', $id)->first();  //Using Eloquent
  46.         echo json_encode(['id' => $data->id_skill, 'skill' => $data->skill_name ]);
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment