Skip to content

Commit

Permalink
Add ViewBuilder::disableAutoLayout().
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Nov 1, 2018
1 parent bc8c37f commit 1a91ee7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Controller/Controller.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ public function render($view = null, $layout = null)
} }


if ($this->request->getParam('bare')) { if ($this->request->getParam('bare')) {
$builder->enableAutoLayout(false); $builder->disableAutoLayout();
} }
$this->autoRender = false; $this->autoRender = false;


Expand Down
15 changes: 15 additions & 0 deletions src/View/ViewBuilder.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -279,6 +279,21 @@ public function enableAutoLayout($enable = true)
return $this; return $this;
} }


/**
* Turns off CakePHP's conventional mode of applying layout files.
*
* Setting to off means that layouts will not be automatically applied to
* rendered views.
*
* @return $this
*/
public function disableAutoLayout()
{
$this->_autoLayout = false;

return $this;
}

/** /**
* Returns if CakePHP's conventional mode of applying layout files is enabled. * Returns if CakePHP's conventional mode of applying layout files is enabled.
* Disabled means that layouts will not be automatically applied to rendered views. * Disabled means that layouts will not be automatically applied to rendered views.
Expand Down
14 changes: 14 additions & 0 deletions tests/TestCase/View/ViewBuilderTest.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -397,4 +397,18 @@ public function testCreateFromArray()
$this->assertEquals(['Html'], $builder->getHelpers()); $this->assertEquals(['Html'], $builder->getHelpers());
$this->assertEquals('JsonView', $builder->getClassName()); $this->assertEquals('JsonView', $builder->getClassName());
} }

/**
* testDisableAutoLayout
*
* @return void
*/
public function testDisableAutoLayout()
{
$builder = new ViewBuilder();
$this->assertNull($builder->isAutoLayoutEnabled());

$builder->disableAutoLayout();
$this->assertFalse($builder->isAutoLayoutEnabled());
}
} }

0 comments on commit 1a91ee7

Please sign in to comment.