Añadimos esto en la vista index:
<li><?php echo $this->Html->link('Ver producto con ID 1', array('controller' => 'cliente', 'action' => 'rest_view', 1)); ?></li> <li><?php echo $this->Html->link('Añadir producto', array('controller' => 'cliente', 'action' => 'rest_add')); ?></li> <li><?php echo $this->Html->link('Actualizar producto 2', array('controller' => 'cliente', 'action' => 'rest_edit', 2)); ?></li> <li><?php echo $this->Html->link('Borrar producto 3', array('controller' => 'cliente', 'action' => 'rest_delete', 3)); ?></li>
Y esto en el controlador:
public function rest_view($id){ $link = $this->url.'rest_productos/'.$id.'.json'; $data = null; $httpSocket = new HttpSocket(); $response = $httpSocket->get($link, $data ); $this->set('response_code', $response->code); $this->set('response_body', $response->body); $this -> render('/Cliente/respuesta'); } public function rest_add(){ $link=$this->url."rest_productos.json"; $data = null; $httpSocket = new HttpSocket(); $data['Producto']['nombre'] = 'Nuevo producto'; $data['Producto']['referencia'] = 'Nueva referencia'; //$data['Phone']['name'] = 'New Phone Description'; $response = $httpSocket->post($link, $data ); $this->set('response_code', $response->code); $this->set('response_body', $response->body); $this -> render('/Cliente/respuesta'); } public function rest_edit($id){ $link = $this->url.'rest_productos/'.$id.'.json'; $data = null; $httpSocket = new HttpSocket(); $data['Producto']['nombre'] = 'Actualizado producto'; $data['Producto']['referencia'] = 'Actualizada referencia'; $response = $httpSocket->put($link, $data ); $this->set('response_code', $response->code); $this->set('response_body', $response->body); $this -> render('/Cliente/respuesta'); } public function rest_delete($id){ // remotely post the information to the server $link = $this->url.'rest_productos/'.$id.'.json'; $data = null; $httpSocket = new HttpSocket(); $response = $httpSocket->delete($link, $data ); $this->set('response_code', $response->code); $this->set('response_body', $response->body); $this -> render('/Cliente/respuesta'); }