Permalink
Browse files

From Controller, look for view in own library

To this point, li3 defaults to app/views. With this change, li3 looks by
default in libraries/foo/views/, where foo is the library containing the
Controller.

remove newlines at EOF
  • Loading branch information...
1 parent b27096c commit a29012a15a2b92dcb7dd6db1b6b43ab4e49577ea @yitznewton yitznewton committed Sep 19, 2012
Showing with 20 additions and 1 deletion.
  1. +4 −1 action/Controller.php
  2. +16 −0 tests/cases/action/ControllerTest.php
View
@@ -10,6 +10,7 @@
use lithium\util\Inflector;
use lithium\action\DispatchException;
+use lithium\core\Libraries;
/**
* The `Controller` class is the fundamental building block of your application's request/response
@@ -243,8 +244,10 @@ public function render(array $options = array()) {
'location' => false,
'data' => null,
'head' => false,
- 'controller' => Inflector::underscore($name)
+ 'controller' => Inflector::underscore($name),
+ 'library' => Libraries::get($class)
);
+
$options += $this->_render + $defaults;
if ($key && $media::type($key)) {
@@ -372,6 +372,22 @@ public function testNonExistentFunction() {
$this->expectException("Action `foo` not found.");
$postsController(new Request(), array('action' => 'foo'));
}
+
+ /**
+ * Tests that the library of the controller is automatically added to the default rendering
+ * options.
+ */
+ public function testLibraryScoping() {
+ $request = new Request();
+ $request->params['controller'] = 'lithium\tests\mocks\action\MockPostsController';
+
+ $controller = new MockPostsController(compact('request') + array('classes' => array(
+ 'media' => 'lithium\tests\mocks\action\MockMediaClass'
+ )));
+
+ $controller->render();
+ $this->assertEqual('lithium', $controller->response->options['library']);
+ }
}
?>

2 comments on commit a29012a

There is small problem, that now controller tries to pull the layout also from library. Before this change I was constantly told, that this feature is unneeded. Now it's implemented into core.

Member

d1rk replied Oct 11, 2012

It should look for the view in the library, then for a layout in the library, but if it does not find one, take the one from app.

Please sign in to comment.