Viewing file: webService.php (3.83 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php if (!defined('BASEPATH')) { exit('No direct script access allowed'); }
define('DIRECCION_API', "http://104.131.18.172:8080/almazen_alfa/"); class webService extends CI_Controller { public function __construct() { parent::__construct(); $this->load->model('consultas_model'); /* Cargamos la base de datos */ $this->load->database(); $this->load->library('javascript'); $this->load->library('session');
/* AƱadimos el helper al controlador */ $this->load->helper('url'); }
public function getProductos() { $this->load->library('curl'); $curl_handle = curl_init(); curl_setopt($curl_handle, CURLOPT_URL, DIRECCION_API . 'product'); $buffer = curl_exec($curl_handle); curl_close($curl_handle); $result = json_decode($buffer); return $result; } public function getClientes() { $this->load->library('curl'); $curl_handle = curl_init(); curl_setopt($curl_handle, CURLOPT_URL, DIRECCION_API . 'client'); $buffer = curl_exec($curl_handle); curl_close($curl_handle); $result = json_decode($buffer); return $result; } //alta de producto public function insertarProducto() {
$postdata = file_get_contents("php://input"); $request = json_decode($postdata);
// accediendo a la base de datos
//accediendo a la api $this->load->library('curl'); $curl_handle = curl_init(); curl_setopt($curl_handle, CURLOPT_URL, DIRECCION_API . 'product');
$data = array('name' => strval($request->name), 'code' => strval($request->numero), 'description' => strval($request->descripcion), 'price' => strval($request->precio), 'sell_price' => strval($request->precio), 'category' => '', 'photo' => '', 'thumbnail' => '', 'vendor' => '', 'stock' => strval($request->stock)); $data_json = json_encode($data); curl_setopt($curl_handle, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); curl_setopt($curl_handle, CURLOPT_POST, 1); curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $data_json); curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true); $buffer = curl_exec($curl_handle); curl_close($curl_handle); $result = json_decode($buffer); var_dump($result);die(); return $result; } //alta de cliente public function insertarCliente() { // accediendo a la base de datos /* { "id": "string", "name": "string", "business_name": "string", "commercial_name": "string", "address": "string", "city": "string", "telephone": "string", "cuit": "string", "mail": "string", "province": "string", "expresso": "string" }
*/
die(); //accediendo a la api $this->load->library('curl'); $curl_handle = curl_init(); curl_setopt($curl_handle, CURLOPT_URL, DIRECCION_API . 'client');
$data = array('username' => 'dog', 'password' => 'tall'); $data_json = json_encode($data); curl_setopt($curl_handle, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); curl_setopt($curl_handle, CURLOPT_POST, 1); curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $data_json); curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true); $buffer = curl_exec($curl_handle); curl_close($curl_handle); $result = json_decode($buffer); return $result; }
public function guardarEdicion() { var_dump($_POST);die(); }
}
|