Skip to content
This repository

From Controller, look for view in own library #650

Merged
merged 1 commit into from over 1 year ago

4 participants

Yitzchak Schaffer Nate Abele Dirk Brünsicke Marius
Yitzchak Schaffer

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

Nate Abele
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!

Yitzchak Schaffer 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
Dirk Brünsicke

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

Nate Abele
Owner

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

Nate Abele nateabele merged commit 1d6fae0 into from
Nate Abele nateabele closed this
Marius

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

Showing 1 unique commit by 1 author.

Sep 19, 2012
Yitzchak Schaffer 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
This page is out of date. Refresh to see the latest.
5  action/Controller.php
@@ -10,6 +10,7 @@
10 10
 
11 11
 use lithium\util\Inflector;
12 12
 use lithium\action\DispatchException;
  13
+use lithium\core\Libraries;
13 14
 
14 15
 /**
15 16
  * The `Controller` class is the fundamental building block of your application's request/response
@@ -243,8 +244,10 @@ public function render(array $options = array()) {
243 244
 			'location'   => false,
244 245
 			'data'       => null,
245 246
 			'head'       => false,
246  
-			'controller' => Inflector::underscore($name)
  247
+			'controller' => Inflector::underscore($name),
  248
+			'library'    => Libraries::get($class)
247 249
 		);
  250
+
248 251
 		$options += $this->_render + $defaults;
249 252
 
250 253
 		if ($key && $media::type($key)) {
16  tests/cases/action/ControllerTest.php
@@ -372,6 +372,22 @@ public function testNonExistentFunction() {
372 372
 		$this->expectException("Action `foo` not found.");
373 373
 		$postsController(new Request(), array('action' => 'foo'));
374 374
 	}
  375
+
  376
+	/**
  377
+	 * Tests that the library of the controller is automatically added to the default rendering
  378
+	 * options.
  379
+	 */
  380
+	public function testLibraryScoping() {
  381
+		$request = new Request();
  382
+		$request->params['controller'] = 'lithium\tests\mocks\action\MockPostsController';
  383
+
  384
+		$controller = new MockPostsController(compact('request') + array('classes' => array(
  385
+			'media' => 'lithium\tests\mocks\action\MockMediaClass'
  386
+		)));
  387
+
  388
+		$controller->render();
  389
+		$this->assertEqual('lithium', $controller->response->options['library']);
  390
+	}
375 391
 }
376 392
 
377 393
 ?>
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.