Наследование: extends Model
Пример #1
0
 public function test_insert_cart()
 {
     $data = array('customer_id' => 1, 'item_id' => 2);
     $_POST = $data;
     $expected = TRUE;
     $Cart_model = new Cart_model();
     $list = $Cart_model->insert_cart();
     $actual = $list['status'];
     $this->assertEquals($expected, $actual);
 }
Пример #2
0
 public function save()
 {
     header("Access-Control-Allow-Origin: *");
     header("Content-Type: application/json; charset=UTF-8");
     $Cart_model = new Cart_model();
     if ($this->_detect_method() == 'post') {
         $result = $Cart_model->insert_item();
         if ($result['status'] === FALSE) {
             print json_encode(array('status' => 'failed', 'error' => 'data error'));
         } else {
             print json_encode(array('id' => $result['status'], 'status' => 'success'));
         }
     } else {
         print json_encode(array('status' => 'failed', 'error' => 'Nothing Post'));
     }
 }
Пример #3
0
 public function add_put()
 {
     $Cart_model = new Cart_model();
     if ($this->_detect_method() == 'put') {
         $result = $Cart_model->insert_cart();
         if ($result['status'] === FALSE) {
             $this->response(['status' => FALSE, 'message' => 'Could not save the item into cart'], REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
             // INTERNAL_SERVER_ERROR (500) being the HTTP response code
         } else {
             $this->response(['status' => TRUE, 'id' => $result['id']], REST_Controller::HTTP_CREATED);
             // CREATED (201) being the HTTP response code
         }
     } else {
         $this->response(['status' => FALSE, 'message' => 'Nothing Post'], REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
         // INTERNAL_SERVER_ERROR (500) being the HTTP response code
     }
 }
Пример #4
0
 function __construct()
 {
     Cart_model::__construct();
 }