Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

From Controller, look for view in own library #650

Merged
merged 1 commit into from

4 participants

@yitznewton

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.

Redo of #639 to point to dev

@nateabele
Owner

Nice, just one thing: it looks like your editor is adding newlines to the end of the files. If you can fix that and squash your commits, I'll merge it ASAP. Thanks!

@yitznewton yitznewton 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
a29012a
@d1rk

That is nice. As i already stated on StackOverflow, the current way to do this is far from perfect. Eager to see that in.

@nateabele
Owner

Hey! Sorry, for whatever reason I didn't get the notification that you updated this, thanks!

@nateabele nateabele merged commit 1d6fae0 into UnionOfRAD:dev

1 check passed

Details default The Travis build passed
@mariuskubilius

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.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 19, 2012
  1. @yitznewton

    From Controller, look for view in own library

    yitznewton authored
    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
This page is out of date. Refresh to see the latest.
Showing with 20 additions and 1 deletion.
  1. +4 −1 action/Controller.php
  2. +16 −0 tests/cases/action/ControllerTest.php
View
5 action/Controller.php
@@ -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)) {
View
16 tests/cases/action/ControllerTest.php
@@ -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']);
+ }
}
?>
Something went wrong with that request. Please try again.