:) hey Chris one of us has better type faster to save the other some trouble ;)
On 11/29/06, Chris Hartjes <[EMAIL PROTECTED]> wrote: > > On 11/29/06, Christoph <[EMAIL PROTECTED]> wrote: > > > > So after all of that, I'm very curious to find out if anyone has gotten > > this to work using CakePHP *native* functionality, which it claims > > (erroneously I think, based on all my tests and attempts to get it > > working) to have. > > > > I decided to take you up on the challenge to show you that you can use > the built-in stuff...but you are missing a whole bunch of steps to > make it happen. I decided to do a very simple example. Google and > actually following the error messages that XML spit out were all the > instructions I really needed. > > I expect this posting to become the main tutorial on how to implement > a web service using the built-in stuff and I will gladly accept > contributions to my PayPal for it ;). I'll put this up on my blog > later for the rest of the world to see. > > 1) turn on internal web services > > Do that by going into core.php and changing the webservices line to say: > > define('WEBSERVICES', 'on'); > > 2) create the controller / action pair that you wish to use to spit > out both XML and HTML depending on your needs > > Here's what the controller I used looks like: > > <?php > > /** > * Test controller for built-in web services > * > * @author Chris Hartjes > * > */ > > class TestController extends AppController > { > var $name = 'Test'; > var $uses = ""; > var $components = array('xml'); > > function index() > { > $message = "This is a test of built-in web services"; > $this->set('message', $message); > } > } > > ?> > > The big thing you missed out on is that you have to also create a > component for spitting out XML, even if it doesn't do anything. So, > I created the component and put it in /app/controllers/xml.php > > <?php > > class XMLComponent extends Object > { > // Blank for now as we're not doing anything weird > } > > ?> > > After I did that, Cake complained that I also needed a helper for XML. > Again, I created a blank one because I'm not doing anything weird. > It goes in /app/views/helpers/xml.php > > <?php > > class XmlHelper extends Helper > { > // blank for now > } > > ?> > > Okay, now we create the view I want to use when we're accessing > non-XML info. This went into /app/views/test/index.thtml > > <?php echo $message ?> > > That's it. > > I decided to keep things simple so I created a blank index.thtml file > in /app/views/test/xml/index.thtml > > Then I created a default XML layout file to spit out the XML. I put > this in /app/views/layouts/xml/default.thtml > > <foo> > <bar><?php echo $message ?></bar> > </foo> > > So, now when I do this: > > mydomain/test > > It spits out the following: > > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> > <html xmlns="http://www.w3.org/1999/xhtml"> > <head> > <title>Verticalscope Stats Reporting System</title> > <link rel="shortcut icon" href="/verticalscope_stats/favicon.ico" > type="image/x-icon" /> > <link rel="stylesheet" type="text/css" > href="/verticalscope_stats/css/cake.generic.css" /><meta > http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head> > <body> > <div id="container"> > <div id="content"> > This is a test of built-in web services </div> > <div id="footer"> > > > </div> > </div> > </body> > </html><!-- 0.2205s --> > > (Note that I have debug set to 1 during these examples) > > When I go to localhost/xml/test I get the following output: > > <foo> > <bar>This is a test of built-in web services</bar> > </foo><!-- 0.2204s --> > > > So, looks like I managed to get it working. I hope this helps people > out who are trying to figure out how to use CakePHP's built-in web > services. > > -- > Chris Hartjes > > "The greatest inefficiencies come from solving problems you will never have." > -- Rasmus Lerdorf > > @TheBallpark - http://www.littlehart.net/attheballpark > @TheKeyboard - http://www.littlehart.net/atthekeyboard > > > > -- == S. DeVore (the old fart) the advice is free, the lack of crankiness will cost you --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---