Skip to content

Commit

Permalink
Add a standalone AjaxView
Browse files Browse the repository at this point in the history
Having a self-contained view class will allow debugkit to continue
working even when the application doesn't have an AjaxView, or when that
AjaxView is not suitable for rendering debugkit.

Refs #416
  • Loading branch information
markstory committed Apr 14, 2016
1 parent c02f0ec commit ac5d16b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/Controller/PanelsController.php
Expand Up @@ -53,7 +53,9 @@ public function beforeFilter(Event $event)
*/
public function beforeRender(Event $event)
{
$this->viewBuilder()->layout('DebugKit.panel')->className('View');
$this->viewBuilder()
->layout('DebugKit.panel')
->className('DebugKit.Ajax');
}

/**
Expand Down Expand Up @@ -87,6 +89,7 @@ public function view($id = null)
$this->Cookie->configKey('debugKit_sort', 'encryption', false);
$this->set('sort', $this->Cookie->read('debugKit_sort'));
$panel = $this->Panels->get($id);

$this->set('panel', $panel);
$this->set(unserialize($panel->content));
}
Expand Down
4 changes: 3 additions & 1 deletion src/Controller/RequestsController.php
Expand Up @@ -48,7 +48,9 @@ public function beforeFilter(Event $event)
*/
public function beforeRender(Event $event)
{
$this->viewBuilder()->layout('DebugKit.toolbar')->className('View');
$this->viewBuilder()
->layout('DebugKit.toolbar')
->className('DebugKit.Ajax');
}

/**
Expand Down
Empty file removed src/Template/Requests/index.ctp
Empty file.
36 changes: 36 additions & 0 deletions src/View/AjaxView.php
@@ -0,0 +1,36 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since 3.2.8
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace DebugKit\View;

use Cake\View\View;

/**
* A view class that is used for AJAX responses.
* Currently only switches the default layout and sets the response type -
* which just maps to text/html by default.
*/
class AjaxView extends View
{
/**
* Initialization hook method.
*
* @return void
*/
public function initialize()
{
parent::initialize();
$this->response->type('ajax');
}
}

0 comments on commit ac5d16b

Please sign in to comment.