Webservice SOAP
De KumbiaPHP Framework Wiki
Modelo: models/services/consulta_service.php
<?php
class ConsultaService {
public function getClientes(){
$lst = new Cliente();
$lst = $lst->find();
$strSync = "";
$strSync = "<?xml version='1.0' encoding='UTF-8'?>";
$strSync .= "<clientes>";
foreach($lst as $cli){
$strSync .="<cliente>";
$strSync .="<id>" . $cli->id . "</id>";
$strSync .="<codigo>" . $cli->codigo . "</codigo>";
$strSync .="<cedula>" . $cli->cedula . "</cedula>";
$strSync .="<nombre>" . $cli->nombre . "</nombre>";
$strSync .="<apellido>" . $cli->apellido . "</apellido>";
$strSync .="<cumple>" . $cli->fecha_de_nacimiento . "</cumple>";
$strSync .="<direccion>" . $cli->direccion . "</direccion>";
$strSync .="<telefono>" . $cli->telefono . "</telefono>";
$strSync .="</cliente>";
}
$strSync .= "</clientes>";
return $strSync;
}
public function modClientes($xmlInput) {
$c = new Cliente();
$actualizable = true;
$xml= simplexml_load_string($xmlInput);
foreach ($xml as $objxml){
$element = $objxml;
$c->codigo = $element->codigo;
$c->cedula = $element->cedula;
$c->nombre = $element->nombre;
$c->apellido = $element->apellido;
$c->direccion = $element->direccion;
$c->telefono = $element->telefono;
if($c->save()) {
}else {
return false;
}
}
return true;
}
}
Controlador: controllers/consulta_service_controller.php
<?php
class ConsultaServiceController extends ApplicationController {
public $template = '';
public $models = array('ciudad','cliente');
public function impl() {
Load::models("services/consulta_service");
ini_set("soap.wsdl_cache_enabled", "0");//Para no tener cache en desarrollo
$server = new SoapServer(null,array('uri' => "http://localhost/kumbia/miapp/consulta_service/impl/"));
$server->setClass("ConsultaService");
ob_end_clean();
$server->handle();
exit;
}
public function index() {
$this->render(null);
}
}
?>
Cliente del webservice, en cualquier vista:
<?php
$client = new SoapClient(null, array('location' => "hhttp://localhost/kumbia/miapp/consulta_service/impl/",'uri' => "http://test-uri/"));
print($client->getClientes());
?>
.