我需要在我的应用程序中呈现一个 XML+XSL 模板,它曾经与 cakePHP 3.0 一起使用。我最近切换到 3.1 并且它已停止工作。问题是我有一个格式化的 XML 视图,而现在我只得到一个纯字符串。
迁移指南说了一些关于RequestHandlerComponent
.
这是我的控制器(与 Cake3.0 完全一样):
<?php
namespace App\Controller;
use App\Controller\AppController;
use Cake\Utility\Xml;
use Cake\Event\Event;
use Cake\Routing\Router;
use Cake\ORM\TableRegistry;
use Cake\Filesystem\Folder;
use Cake\Filesystem\File;
use Cake\Network\Email\Email;
use Cake\Core\Configure;
use Cake\I18n\Time;
/**
* Invoices Controller
*
* @property App\Model\Table\InvoicesTable $Invoices
*/
class InvoicesController extends AppController
{
public $components = [
'Browser',
'Reorder11'
];
public $helpers = [
'Multiple'
];
public $paginate = [];
public function initialize()
{
parent::initialize();
$this->loadComponent('Paginator');
$this->loadComponent('RequestHandler');
}
public function beforeFilter(Event $event)
{
parent::beforeFilter($event);
$this->Auth->allow(['demo']);
}
/*
* ... several other functions ...
*/
public function viewxml($id = null)
{
$this->viewBuilder()->layout('xml');
$invoice = $this->Invoices->myInvoice($id, $this->Auth->user('id'));
$this->RequestHandler->respondAs('xml');
$this->set('invoice', $invoice);
}
}
布局,xml.ctp
真的很简单
echo $this->fetch('content');
并且viewxml.ctp
模板只是将 xml 作为字符串回显。
如何再次获取格式化的 XML+XSL?