mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Ensure callbacks are triggered when using Xml/Json view with view templates.
PaginatorHelper for instance needs this to correctly set options
This commit is contained in:
parent
62dd39133b
commit
e7dc23b920
4 changed files with 9 additions and 14 deletions
|
@ -76,6 +76,7 @@ class JsonViewTest extends CakeTestCase {
|
|||
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)
|
||||
));
|
||||
$Request = new CakeRequest();
|
||||
$Request->params['named'] = array('page' => 2);
|
||||
$Response = new CakeResponse();
|
||||
$Controller = new Controller($Request, $Response);
|
||||
$Controller->name = $Controller->viewPath = 'Posts';
|
||||
|
@ -91,9 +92,10 @@ class JsonViewTest extends CakeTestCase {
|
|||
);
|
||||
$Controller->set('user', $data);
|
||||
$View = new JsonView($Controller);
|
||||
$View->helpers = array('Paginator');
|
||||
$output = $View->render('index');
|
||||
|
||||
$expected = json_encode(array('user' => 'fake', 'list' => array('item1', 'item2')));
|
||||
$expected = json_encode(array('user' => 'fake', 'list' => array('item1', 'item2'), 'paging' => array('page' => 2)));
|
||||
$this->assertSame($expected, $output);
|
||||
$this->assertSame('application/json', $Response->type());
|
||||
}
|
||||
|
|
|
@ -16,9 +16,12 @@
|
|||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
$paging = isset($this->Paginator->options['url']) ? $this->Paginator->options['url'] : null;
|
||||
|
||||
$formatted = array(
|
||||
'user' => $user['User']['username'],
|
||||
'list' => array()
|
||||
'list' => array(),
|
||||
'paging' => $paging,
|
||||
);
|
||||
foreach ($user['Item'] as $item) {
|
||||
$formatted['list'][] = $item['name'];
|
||||
|
|
|
@ -85,12 +85,7 @@ class JsonView extends View {
|
|||
return $this->_serialize($this->viewVars['_serialize']);
|
||||
}
|
||||
if ($view !== false && $viewFileName = $this->_getViewFileName($view)) {
|
||||
if (!$this->_helpersLoaded) {
|
||||
$this->loadHelpers();
|
||||
}
|
||||
$content = $this->_render($viewFileName);
|
||||
$this->Blocks->set('content', $content);
|
||||
return $content;
|
||||
return parent::render($view, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -88,12 +88,7 @@ class XmlView extends View {
|
|||
return $this->_serialize($this->viewVars['_serialize']);
|
||||
}
|
||||
if ($view !== false && $viewFileName = $this->_getViewFileName($view)) {
|
||||
if (!$this->_helpersLoaded) {
|
||||
$this->loadHelpers();
|
||||
}
|
||||
$content = $this->_render($viewFileName);
|
||||
$this->Blocks->set('content', (string)$content);
|
||||
return $content;
|
||||
return parent::render($view, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue