Skip to content

Commit

Permalink
Set viewPath correctly for prefix controllers.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Jul 4, 2012
1 parent 752e039 commit c68f8b2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/Cake/Controller/Controller.php
Expand Up @@ -329,7 +329,11 @@ public function __construct($request = null, $response = null) {
}

if ($this->viewPath == null) {
$this->viewPath = $this->name;
$viewPath = $this->name;
if (isset($request->params['prefix'])) {
$viewPath = Inflector::camelize($request->params['prefix']) . DS . $viewPath;
}
$this->viewPath = $viewPath;
}
if ($this->_mergeParent === null) {
$this->_mergeParent = Configure::read('App.namespace') . '\Controller\Controller';
Expand Down
19 changes: 19 additions & 0 deletions lib/Cake/Test/TestCase/Controller/ControllerTest.php
Expand Up @@ -1444,4 +1444,23 @@ public function testInvokeActionReturnValue() {
$this->assertEquals('I am from the controller.', $result);
}

/**
* test that a classes namespace is used in the viewPath.
*
* @return void
*/
public function testViewPathConventions() {
$request = new Request('admin/posts');
$request->addParams(array(
'prefix' => 'admin'
));
$response = $this->getMock('Cake\Network\Response');
$Controller = new \TestApp\Controller\Admin\PostsController($request, $response);
$this->assertEquals('Admin/Posts', $Controller->viewPath);

$request = new Request('pages/home');
$Controller = new \TestApp\Controller\PagesController($request, $response);
$this->assertEquals('Pages', $Controller->viewPath);
}

}

0 comments on commit c68f8b2

Please sign in to comment.