Sunday, 4 October 2015

Generate XML file in Cakephp

Steps to Generate XML file using CakePHP:

Step-1 Enable to parse xml extension in config route.php file.
    Router::parseExtensions('xml');
Step-2 Add Request Handler Component to the Controller
   var $components = array(‘RequestHandler’);
Step-3 Add controller Action For XML Generation in Post Controller
    function generateXMLFile()
    {
        if ($this->RequestHandler->isXml()) { // check request type
            $this->layout = 'empty'; // create an empty layout in app/views/layouts/empty.ctp   
         }   
    }
 Add header code in empty layout
<?php header('Content-type: text/xml');?>
<?php echo $this->Xml->header(); ?>
<?php echo $content_for_layout; ?>

Step-4 Set up View To generate XML
Create xml folder inside Posts view and file name is generateXMLFile.ctp
"view/Posts/xml/generateXMLFile.ctp"
<response>
       <posts>
              <Post>
                     <id>test 234</id>
              </Post>
       </posts>
</response>


 Step-5 Set action request by HTML Helper
 <?php echo $this->Html->link( __('Generate XML', true), array('action'=>'generateXMLFile','ext'=>'xml'),
array('class'=>'button','target'=>'_blank') ); ?>
 

31 comments:

  1. I am newbie of this PHP technology, this post helps me to know the introductory of PHP, Thanks for posting such a nice post.
    Regards,
    PHP Training in Chennai|PHP Course in Chennai

    ReplyDelete
    Replies
    1. Thanks Melisa, If you need PHP development help drop me mail.

      Delete
  2. Generating XML with CakePHP is a very easy start with routes.php. XML is very useful for the data transfer over the web.

    CakePHP Training Center in Jaipur.

    ReplyDelete
    Replies
    1. Thanks Ankita, You need any more help. Let me know

      Delete
  3. What as up, I read your blogs like every week. Your writing style is awesome, keep up the good work!
    Hadoop Online Training Real Time Support From India

    ReplyDelete
  4. This is excellent information. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    Android Training in Chennai
    Ios Training in Chennai

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. It’s always so sweet and also full of a lot of fun for me personally and my office colleagues to search your blog a minimum of thrice in a week to see the new guidance you have got.
    big data training in bangalore

    ReplyDelete
  7. Thanks a lot very much for the high your blog post quality and results-oriented help. I won’t think twice to endorse to anybody who wants and needs support about this area. data science training in jaya nagar

    ReplyDelete
  8. I simply wanted to write down a quick word to say thanks to you for those wonderful tips and hints you are showing on this site.
    dotnet training in bangalore

    ReplyDelete
  9. I feel really happy to have seen your webpage and look forward to so many more entertaining times reading here. Thanks once more for all the details.
    hadoop-training-in-bangalore

    ReplyDelete
  10. This is very good blog for learners, Thanks for sharing valuable content on MSBI Online Training

    ReplyDelete
  11. Excellent blog.. Thank you so much for sharing this nice blog, it was so good to read and useful to improve my knowledge as updated one, keep on going such a nice blog. Summer Camp for Computer Science in Velachery | Summer classes for Computer Science in Velachery | Summer courses for Computer Science in Taramani

    ReplyDelete
  12. It’s really nice and meaningful. it’s really cool blog. Linking is very useful thing.you have really helped lots of people who visit blog and provide them useful information.
    Excellent Vacation Courses in Chennai | Good Summer Course in Guindy

    ReplyDelete
  13. Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.
    Hadoop Training Institute In chennai

    amazon-web-services-training-institute-in-chennai

    ReplyDelete
  14. I ‘d mention that most of us visitors are endowed to exist in a fabulous place with very many wonderful individuals with very helpful things.
    uipath training in bangalore

    ReplyDelete
  15. Appreciation for really being thoughtful and also for deciding on certain marvelous guides most people really want to be aware of.
    Best selenium training Institute in chennai

    ReplyDelete
  16. This comment has been removed by a blog administrator.

    ReplyDelete
  17. This comment has been removed by the author.

    ReplyDelete
  18. This comment has been removed by the author.

    ReplyDelete
  19. This comment has been removed by the author.

    ReplyDelete
  20. This comment has been removed by a blog administrator.

    ReplyDelete
  21. This comment has been removed by a blog administrator.

    ReplyDelete
  22. My spouse and I love your blog and find almost all of your post’s to be just what I’m looking for. can you offer guest writers to write content for you? I wouldn’t mind producing a post or elaborating on some the subjects you write concerning here. Again, awesome weblog!

    Hadoop Training in Chennai

    ReplyDelete
  23. Wonderful blog!!! I liked the complete article…. great written,Thanks for all the information you have provided…
    Graphics Designing Training Institute in Chennai | Best Multimedia Courses in Velachery

    ReplyDelete