PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, March 15, 2022

[FIXED] CakePHP 3 creating XML view

 March 15, 2022     cakephp, cakephp-3.0, xml     No comments   

Issue

I need to convert an array to an XML response. The objective is to write a function within a plugin controller and call it, which would return an XML response.

I've been trying this below mentioned code from the CakePHP manual.

   namespace App\Controller;

   class ArticlesController extends AppController{

       public function initialize(){
            parent::initialize();
            $this->loadComponent('RequestHandler');
       }

       public function index(){

            // Set the view vars that have to be serialized.
            $this->set('articles', $this->paginate());
            // Specify which view vars JsonView should serialize.
            $this->set('_serialize', ['articles']);
       }
    }

Is there a way I can debug or pr the response and see how exactly the XML response will look like?


Solution

in routes.php, insert

Router::extensions('xml');

just before

Router::defaultRouteClass('DashedRoute');

then, just use ".xml" in yout action:

/yourController/index.xml



Answered By - Fabio Colombini
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing