BUGFIX: Added better handling of rendering SiteTree objects, to prevent test errors. (from r89963)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@96729 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2010-01-12 23:06:59 +00:00
parent 5296f59d23
commit 2b717a1ea5
3 changed files with 25 additions and 2 deletions

View File

@ -280,7 +280,12 @@ class Director {
$controllerObj = new $controller(); $controllerObj = new $controller();
$controllerObj->setSession($session); $controllerObj->setSession($session);
return $controllerObj->handleRequest($request); $result = $controllerObj->handleRequest($request);
if(!is_object($result) || $result instanceof HTTPResponse) return $result;
user_error("Bad result from url " . $request->getURL() . " handled by " .
get_class($controllerObj)." controller: ".get_class($result), E_USER_WARNING);
} }
} }
} }

View File

@ -17,7 +17,8 @@ class ModelAsController extends Controller implements NestedController {
* @return ContentController * @return ContentController
*/ */
public static function controller_for(SiteTree $sitetree, $action = null) { public static function controller_for(SiteTree $sitetree, $action = null) {
$controller = "{$sitetree->class}_Controller"; if($sitetree->class == 'SiteTree') $controller = "ContentController";
else $controller = "{$sitetree->class}_Controller";
if($action && class_exists($controller . '_' . ucfirst($action))) { if($action && class_exists($controller . '_' . ucfirst($action))) {
$controller = $controller . '_' . ucfirst($action); $controller = $controller . '_' . ucfirst($action);
@ -54,6 +55,9 @@ class ModelAsController extends Controller implements NestedController {
if($result instanceof RequestHandler) { if($result instanceof RequestHandler) {
$result = $result->handleRequest($this->request); $result = $result->handleRequest($this->request);
} else if(!($result instanceof HTTPResponse)) {
user_error("ModelAsController::getNestedController() returned bad object type '" .
get_class($result)."'", E_USER_WARNING);
} }
} catch(SS_HTTPResponse_Exception $responseException) { } catch(SS_HTTPResponse_Exception $responseException) {
$result = $responseException->getResponse(); $result = $responseException->getResponse();

View File

@ -0,0 +1,14 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<!-- very simple template that exists mainly so that edge cases like test execution don't fail -->
<head>
<% base_tag %>
$MetaTags
</head>
<body>
<h1>$Title</h1>
$Content
<p><i>Generated with the default ContentController.ss template</i></p>
</body>
</html>