Wednesday, May 2, 2012

Re: get output controller from another controller

Hello,

Unfortunately the output format (in my variable) is still not the REST XML.

Any other idea?

Thanks
Christophe

On Sat, Apr 28, 2012 at 6:31 AM, lowpass <zijn.digital@gmail.com> wrote:
> I don't know if this is all you need but these might help:
>
> $this->response->type('xml');
> $this->viewPath = 'events';
> $this->view = 'view';  // assuming app/views/events/view.ctp
>
> On Fri, Apr 27, 2012 at 2:45 AM, Christophe Vandeplas
> <christophe@vandeplas.com> wrote:
>> Hello,
>>
>>
>> ( using CakePHP 2.1 )
>> I'm building an application that synchronizes data between different
>> instances of my application. (download and upload)
>>
>> My application is REST enabled and thus I can call controller actions
>> from external applications and get the result in clean xml. However it
>> is not only a REST server, but also a REST client.
>>
>> Downloading data from the other instance is easy. I do a $xml =
>> Xml::build($xmlurl); and process the $xml variable to import
>> everything into my database. Perfect.
>>
>> However I am stuck in the other direction: Uploading data.
>> I could simply do a $xmldata = Xml::fromArray($event)->asXML() however
>> there is some cleaning to be done. This cleaning is what I do in my
>> REST view as my REST clients should see the same xml as what I'm
>> uploading to the other instance.
>> So if I already do all the work in my rest view, why recoding exactly
>> the same filtering?
>>
>> The url /events/view/5.xml  calls  EventsController->view(5) with XML
>> layout and outputs everything in XML, exactly as I want it.
>>
>> I have a ServersController->push() function.
>> This function needs to do get the same output as /events/view/5.xml ,
>> and upload it using a REST POST request to the other instance.
>>
>> You could say I could simply call the /events/view/5.xml page using an
>> HTTP request from the application.
>> However it seems absurd as i) it seems absurd (and inefficient/slow)
>> to do HTTP requests to yourself to extract data and ii) I have
>> authentication on my REST calls which makes it a lot more difficult.
>>
>> I tried with :
>> $eventsController = new EventsController();
>> $eventsController->set('event', $event);
>> $view = new View($eventsController);
>> $viewdata = $view->render('view');
>>
>> But this only outputs the data in HTML, and not XML.
>> I tried to play with the CakeResponse object in that newly created
>> $eventsController, but that doesn't work. (there are no request or
>> response instances created, and creating them myself doesn't work)
>>
>>
>> So my question is:
>> What is the best way to get the output of /events/view/5.xml
>> (EventsController->view(5) ) inside another controller ?
>>
>>
>> Thanks for your expertise.
>> Christophe
>>
>> --
>> Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
>> Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
>>
>>
>> To unsubscribe from this group, send email to
>> cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
>
> --
> Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
>
>
> To unsubscribe from this group, send email to
> cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: