Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php if (!defined('BASEPATH')) {exit('No direct script access allowed');
- }
- //Add data-controller
- class AddData extends CI_Controller {
- public function __construct() {
- parent::__construct();
- }
- public function index() {
- $this->load->view('addData_view');
- }
- public function insertData_controller() {
- $s = $this->input->post('so');
- $g = $this->input->post('gia');
- //truyền dữ liệu vào model
- //gọi model
- $this->load->model('addData_model');
- $query = $this->addData_model->insert($s, $g);
- if ($query) {
- $this->load->view('insertThanhcong');
- } else {
- echo 'insert that bai';
- }
- }
- }
- /* End of file AddData.php */
- /* Location: ./application/controllers/AddData.php */
- //showData_controller
- <?php if (!defined('BASEPATH')) {exit('No direct script access allowed');
- }
- class showData extends CI_Controller {
- public function __construct() {
- parent::__construct();
- }
- public function index() {
- //load model
- $this->load->model('showData_model');
- $ketqua = $this->showData_model->getData();
- //bien du lieu thanh mang thông qua key dlcontroller
- $dulieu = array('dlcontroller' => $ketqua);
- //load view và truyền biến dữ liệu $data cho view,
- $this->load->view('showData_view', $dulieu);
- }
- public function deleteData($id) {
- // echo $id;
- $this->load->model('showData_model');
- $kq = $this->showData_model->deleteDataById($id);
- if ($kq) {
- $this->load->view('xoathanhcong');
- } else {
- echo 'xoa that bai';
- }
- }
- public function editDataById($id) {
- $this->load->model('showData_model');
- $kq = $this->showData_model->editDataById($id);
- //biến mảng $kq lấy từ model -> mảng mangkq để chuyển sang view,.
- $kq = array('mangkq' => $kq);
- $this->load->view('editData_view', $kq);
- }
- public function updateData() {
- $id = $this->input->post('id');
- $so = $this->input->post('so');
- $gia = $this->input->post('gia');
- $this->load->model('showData_model');
- $kq = $this->showData_model->updateDataById($id, $so, $gia);
- if ($kq) {
- $this->load->view('insertThanhcong');
- } else {
- echo 'update du lieu that bai';
- }
- }
- }
- /* End of file showData.php */
- /* Location: ./application/controllers/showData.php */
- //addData-model
- <?php if (!defined('BASEPATH')) {exit('No direct script access allowed');
- }
- class addData_model extends CI_Model {
- public $variable;
- public function __construct() {
- parent::__construct();
- }
- public function insert($so, $gia) {
- $dulieu = array('so' => $so, 'price' => $gia);
- $this->db->insert('so_sims', $dulieu);
- return $this->db->insert_id();
- //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
- }
- }
Add Comment
Please, Sign In to add comment