Skip to content

Instantly share code, notes, and snippets.

@bendo01
Created April 2, 2013 11:12
Show Gist options
  • Save bendo01/5291505 to your computer and use it in GitHub Desktop.
Save bendo01/5291505 to your computer and use it in GitHub Desktop.
creating soap server on cakephp 2.x and following this tutorial http://mykm.wordpress.com/2008/01/23/implementing-soap-server-on-cakephp/#comment-136
<?php
App::uses('AppController', 'Controller');
App::uses('Post', 'Model'); //this is important don't forget to add this
/**
* Posts Controller
*
* @property Post $Post
*/
class PostsController extends AppController {
var $components = array('RequestHandler');
/**
* index method
*
* @return void
*/
public function index() {
$this->Post->recursive = 0;
$this->set('posts', $this->paginate());
}
/**
* view method
*
* @throws NotFoundException
* @param string $id
* @return void
*/
public function view($id = null) {
if (!$this->Post->exists($id)) {
throw new NotFoundException(__('Invalid post'));
}
$options = array('conditions' => array('Post.' . $this->Post->primaryKey => $id));
$this->set('post', $this->Post->find('first', $options));
}
/**
* add method
*
* @return void
*/
public function add() {
if ($this->request->is('post')) {
$this->Post->create();
if ($this->Post->save($this->request->data)) {
$this->Session->setFlash(__('The post has been saved'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The post could not be saved. Please, try again.'));
}
}
}
/**
* edit method
*
* @throws NotFoundException
* @param string $id
* @return void
*/
public function edit($id = null) {
if (!$this->Post->exists($id)) {
throw new NotFoundException(__('Invalid post'));
}
if ($this->request->is('post') || $this->request->is('put')) {
if ($this->Post->save($this->request->data)) {
$this->Session->setFlash(__('The post has been saved'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The post could not be saved. Please, try again.'));
}
} else {
$options = array('conditions' => array('Post.' . $this->Post->primaryKey => $id));
$this->request->data = $this->Post->find('first', $options);
}
}
/**
* delete method
*
* @throws NotFoundException
* @throws MethodNotAllowedException
* @param string $id
* @return void
*/
public function delete($id = null) {
$this->Post->id = $id;
if (!$this->Post->exists()) {
throw new NotFoundException(__('Invalid post'));
}
$this->request->onlyAllow('post', 'delete');
if ($this->Post->delete()) {
$this->Session->setFlash(__('Post deleted'));
$this->redirect(array('action' => 'index'));
}
$this->Session->setFlash(__('Post was not deleted'));
$this->redirect(array('action' => 'index'));
}
function service() {
$this->layout = false;
$this->autoRender = false;
Configure::write('debug', 0);
ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
$server = new SoapServer('http://localhost/blogpostsoapserver/posts/wsdl');
$server->setClass("Post");
$server->handle();
}
function wsdl() {
$this->layout = false;
Configure::write('debug', 0);
$this->RequestHandler->respondAs('xml');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment