Guest User

Untitled

a guest
Feb 20th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. <?php if (!defined('BASEPATH')) {exit('No direct script access allowed');
  2. }
  3. //Add data-controller
  4. class AddData extends CI_Controller {
  5.  
  6. public function __construct() {
  7. parent::__construct();
  8. }
  9.  
  10. public function index() {
  11. $this->load->view('addData_view');
  12. }
  13. public function insertData_controller() {
  14. $s = $this->input->post('so');
  15. $g = $this->input->post('gia');
  16. //truyền dữ liệu vào model
  17. //gọi model
  18. $this->load->model('addData_model');
  19. $query = $this->addData_model->insert($s, $g);
  20. if ($query) {
  21. $this->load->view('insertThanhcong');
  22. } else {
  23. echo 'insert that bai';
  24. }
  25.  
  26. }
  27.  
  28. }
  29. /* End of file AddData.php */
  30. /* Location: ./application/controllers/AddData.php */
  31.  
  32.  
  33.  
  34. //showData_controller
  35. <?php if (!defined('BASEPATH')) {exit('No direct script access allowed');
  36. }
  37.  
  38. class showData extends CI_Controller {
  39.  
  40. public function __construct() {
  41. parent::__construct();
  42. }
  43.  
  44. public function index() {
  45.  
  46. //load model
  47. $this->load->model('showData_model');
  48. $ketqua = $this->showData_model->getData();
  49. //bien du lieu thanh mang thông qua key dlcontroller
  50. $dulieu = array('dlcontroller' => $ketqua);
  51. //load view và truyền biến dữ liệu $data cho view,
  52. $this->load->view('showData_view', $dulieu);
  53. }
  54. public function deleteData($id) {
  55. // echo $id;
  56. $this->load->model('showData_model');
  57. $kq = $this->showData_model->deleteDataById($id);
  58. if ($kq) {
  59. $this->load->view('xoathanhcong');
  60. } else {
  61. echo 'xoa that bai';
  62. }
  63. }
  64. public function editDataById($id) {
  65. $this->load->model('showData_model');
  66. $kq = $this->showData_model->editDataById($id);
  67. //biến mảng $kq lấy từ model -> mảng mangkq để chuyển sang view,.
  68. $kq = array('mangkq' => $kq);
  69. $this->load->view('editData_view', $kq);
  70.  
  71. }
  72. public function updateData() {
  73. $id = $this->input->post('id');
  74. $so = $this->input->post('so');
  75. $gia = $this->input->post('gia');
  76.  
  77. $this->load->model('showData_model');
  78. $kq = $this->showData_model->updateDataById($id, $so, $gia);
  79. if ($kq) {
  80. $this->load->view('insertThanhcong');
  81. } else {
  82. echo 'update du lieu that bai';
  83. }
  84.  
  85. }
  86.  
  87. }
  88.  
  89. /* End of file showData.php */
  90. /* Location: ./application/controllers/showData.php */
  91.  
  92. //addData-model
  93. <?php if (!defined('BASEPATH')) {exit('No direct script access allowed');
  94. }
  95.  
  96. class addData_model extends CI_Model {
  97.  
  98. public $variable;
  99.  
  100. public function __construct() {
  101. parent::__construct();
  102.  
  103. }
  104. public function insert($so, $gia) {
  105. $dulieu = array('so' => $so, 'price' => $gia);
  106. $this->db->insert('so_sims', $dulieu);
  107. return $this->db->insert_id();
  108. //cần khai báo giá trị trả về thì câu lênh if bên controller mới thực hiện đúng được điều kiện
  109.  
  110. }
  111.  
  112. }
Add Comment
Please, Sign In to add comment