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.
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
                     <id>test 234</id>

 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') ); ?>


  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.
    PHP Training in Chennai|PHP Course in Chennai

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

  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.

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

  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

  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

  5. This comment has been removed by the author.