Skip to content
Permalink
Browse files

Allow having prefix specific layouts.

Refs #3907
  • Loading branch information...
ADmad committed Jul 10, 2014
1 parent 2ae1fd9 commit f49408c8f58fbb9d36b25d40ee954cc104e89b18
@@ -977,14 +977,25 @@ protected function _getLayoutFileName($name = null) {
}
list($plugin, $name) = $this->pluginSplit($name);
$paths = $this->_paths($plugin);
$file = 'Layout' . DS . $subDir . $name;
$layoutPaths = ['Layout' . DS . $subDir];
if (!empty($this->request->params['prefix'])) {
array_unshift(
$layoutPaths,
Inflector::camelize($this->request->params['prefix']) . DS . $layoutPaths[0]
);
}
foreach ($paths as $path) {
if (file_exists($path . $file . $this->_ext)) {
return $path . $file . $this->_ext;
foreach ($layoutPaths as $layoutPath) {
if (file_exists($path . $layoutPath . $name . $this->_ext)) {
return $path . $layoutPath . $name . $this->_ext;
}
}
}
throw new Error\MissingLayoutException(array('file' => $file . $this->_ext));
throw new Error\MissingLayoutException(array(
'file' => $layoutPath[0] . $name . $this->_ext
));
}
/**
@@ -596,6 +596,29 @@ public function testGetLayoutFileNamePlugin() {
$this->assertPathEquals($expected, $result);
}
/**
* Test getting layout filenames for prefix
*
* @return void
*/
public function testGetLayoutFileNamePrefix() {
$View = new TestView();
// Prefix specific layout
$View->request->params['prefix'] = 'FooPrefix';
$expected = TEST_APP . 'TestApp' . DS . 'Template' . DS .
'FooPrefix' . DS . 'Layout' . DS . 'default.ctp';
$result = $View->getLayoutFileName();
$this->assertPathEquals($expected, $result);
// Fallback to app's layout
$View->request->params['prefix'] = 'Admin';
$expected = TEST_APP . 'TestApp' . DS . 'Template' . DS .
'Layout' . DS . 'default.ctp';
$result = $View->getLayoutFileName();
$this->assertPathEquals($expected, $result);
}
/**
* Test for missing views
*
@@ -0,0 +1 @@
Default layout for FooPrefix prefix.

0 comments on commit f49408c

Please sign in to comment.
You can’t perform that action at this time.