For CakePHP 1.1xxx
Here are the things I did to get it to work at a bare minimum for a
REST style service
Turn on webservices in config/core.php by uncommenting this line (or changing ‘off’ to ‘on’)
`define(‘WEBSERVICES’, ‘on’);`
make a rest.php file in controllers/components
PHP
-
<?php
-
class RestComponent extends Object {
-
}
-
?>
make a rest.php file in views/helpers
PHP
-
<?php
-
class RestHelper extends Helper
-
{
-
}
-
?>
in views/layouts make a folder called ‘rest’ and put a default.thtml file in it
-
<?php echo $content_for_layout; ?>
for the controller that you want a rest service make a folder called
rest in views/controllername/
in there put the view for the action like
XML
-
<?php e(‘<?xml version="1.0" encoding="utf-8" ?>‘);
-
if (isset($applications) and !empty($applications)) : ?>
-
<rsp stat="ok">
-
<applications type=’array‘>
-
<?php foreach ($applications as $application) : ?>
-
<application type=’struct‘>
-
<name><?php e($application['Application']['name'])?></name>
-
<version><?php e($application['Version'][0]['value'])?></version>
-
</application>
-
<?php endforeach; ?>
-
</applications>
-
<?php else: ?>
-
<rsp stat="fail">
-
<err type=’struct‘>
-
<?php if ($session->check(‘Message.flash’)): ?>
-
<msg><?php e(strip_tags($session->read(‘Message.flash’)));?></msg>
-
<?php endif; ?>
-
</err>
-
<?php endif; ?>
In the controller you can add logic like below to control output paths based on the service.
PHP
-
if ($this->params[‘webservices’] == ‘Rest’) {
-
$this->set(‘order’,$this->Order->read());
-
}
-
else {
-
$this->redirect(‘/orders/index’);
-
}
I’ll work on fleshing this out later and then finish the article I started in the bakery, I promise.