fork download
  1. application/
  2. ├── controllers/
  3. │ └── Employee.php
  4. ├── models/
  5. │ └── Employee_model.php
  6. ├── views/
  7. │ ├── employee_list.php
  8. │ ├── employee_add.php
  9. │ ├── employee_delete.php
  10. │ └── employee_view.php (Optional - for viewing details)
  11.  
  12. <?php
  13. defined('BASEPATH') OR exit('No direct script access allowed');
  14.  
  15. class Employee extends CI_Controller {
  16.  
  17. public function __construct() {
  18. parent::__construct();
  19. $this->load->model('Employee_model'); // Load the model
  20. }
  21.  
  22. public function index() {
  23. $data['employees'] = $this->Employee_model->get_all_employees();
  24. $this->load->view('employee_list', $data);
  25. }
  26.  
  27. public function add() {
  28. if ($this->input->post()) {
  29. $this->Employee_model->add_employee($this->input->post());
  30. redirect('employee'); // Redirect to the employee list
  31. }
  32. $this->load->view('employee_add');
  33. }
  34.  
  35. public function delete($empno) {
  36. $this->Employee_model->delete_employee($empno);
  37. redirect('employee');
  38. }
  39. //Optional View Function
  40. public function view($empno){
  41. $data['employee'] = $this->Employee_model->get_employee($empno);
  42. $this->load->view('employee_view', $data);
  43. }
  44.  
  45. }
Success #stdin #stdout 0.03s 25456KB
stdin
-- Create the database
CREATE DATABASE IF NOT EXISTS employee_db;

-- Use the database
USE employee_db;

-- Create the EMPLOYEE table
CREATE TABLE EMPLOYEE (
    EMPNO INT NOT NULL,
    FIRSTNME VARCHAR(12) NOT NULL,
    MIDINIT CHAR(1) NOT NULL,
    LASTNAME VARCHAR(15) NOT NULL,
    WORKDEPT CHAR(3),
    PRIMARY KEY (EMPNO)
);
stdout
application/
├── controllers/
│   └── Employee.php
├── models/
│   └── Employee_model.php
├── views/
│   ├── employee_list.php
│   ├── employee_add.php
│   ├── employee_delete.php
│   └── employee_view.php  (Optional - for viewing details)

No direct script access allowed