Added logging of SSViewer and Controller behaviour when using ?debug_request=1

API CHANGE: Template precedence changed.  Page_results now takes precedence over HomePage.  That is, all action templates of parent classes take precedence over the actionless templates.

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@60711 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2008-08-14 03:35:13 +00:00
parent e7cbdbc07d
commit 50790d8098
3 changed files with 22 additions and 11 deletions

View File

@ -39,6 +39,7 @@ class SSViewer extends Object {
$this->chosenTemplates['main'] = $templateList; $this->chosenTemplates['main'] = $templateList;
} else { } else {
if(!is_array($templateList)) $templateList = array($templateList); if(!is_array($templateList)) $templateList = array($templateList);
if(isset($_GET['debug_request'])) Debug::message("Selecting templates from the following list: " . implode(", ", $templateList));
$this->chosenTemplates = array(); $this->chosenTemplates = array();
global $_TEMPLATE_MANIFEST; global $_TEMPLATE_MANIFEST;
@ -49,13 +50,15 @@ class SSViewer extends Object {
else $templateFolder = null; else $templateFolder = null;
// Base templates // Base templates
if(isset($_TEMPLATE_MANIFEST[$template])) { if(isset($_TEMPLATE_MANIFEST[$template]) && (array_keys($_TEMPLATE_MANIFEST[$template]) != array('themes'))) {
$this->chosenTemplates = array_merge($_TEMPLATE_MANIFEST[$template], $this->chosenTemplates); $this->chosenTemplates = array_merge($_TEMPLATE_MANIFEST[$template], $this->chosenTemplates);
if(isset($_GET['debug_request'])) Debug::message("Found template '$template' from main template archive, containing the following items: " . var_export($_TEMPLATE_MANIFEST[$template], true));
unset($this->chosenTemplates['themes']); unset($this->chosenTemplates['themes']);
} }
// Use the theme template if available // Use the theme template if available
if(self::$current_theme && isset($_TEMPLATE_MANIFEST[$template]['themes'][self::$current_theme])) { if(self::$current_theme && isset($_TEMPLATE_MANIFEST[$template]['themes'][self::$current_theme])) {
if(isset($_GET['debug_request'])) Debug::message("Found template '$template' from main theme '" . self::$current_theme . "': " . var_export($_TEMPLATE_MANIFEST[$template]['themes'][self::$current_theme], true));
$this->chosenTemplates = array_merge($_TEMPLATE_MANIFEST[$template]['themes'][self::$current_theme], $this->chosenTemplates = array_merge($_TEMPLATE_MANIFEST[$template]['themes'][self::$current_theme],
$this->chosenTemplates); $this->chosenTemplates);
} }
@ -65,6 +68,9 @@ class SSViewer extends Object {
unset($this->chosenTemplates[$templateFolder]); unset($this->chosenTemplates[$templateFolder]);
} }
} }
if(isset($_GET['debug_request'])) Debug::message("Final template selections made: " . var_export($this->chosenTemplates, true));
} }
if(!$this->chosenTemplates) user_error("None of these templates can be found: ". implode(".ss, ", $templateList) . ".ss", E_USER_WARNING); if(!$this->chosenTemplates) user_error("None of these templates can be found: ". implode(".ss, ", $templateList) . ".ss", E_USER_WARNING);

View File

@ -226,19 +226,22 @@ class Controller extends RequestHandlingData {
} else if($this->template) { } else if($this->template) {
$templates = $this->template; $templates = $this->template;
} else { } else {
$parentClass = $this->class;
if($action && $action != 'index') {
$parentClass = $this->class; $parentClass = $this->class;
while($parentClass != "Controller") { while($parentClass != "Controller") {
$templateName = $parentClass; $templates[] = strtok($parentClass,'_') . '_' . $action;
if(($pos = strpos($templateName,'_')) !== false) $templateName = substr($templateName, 0, $pos);
if($action && $action != "index") $templates[] = $templateName . '_' . $action;
$templates[] = $templateName;
$parentClass = get_parent_class($parentClass); $parentClass = get_parent_class($parentClass);
} }
}
$parentClass = $this->class;
while($parentClass != "Controller") {
$templates[] = strtok($parentClass,'_');
$parentClass = get_parent_class($parentClass);
}
$templates = array_unique($templates); $templates = array_unique($templates);
} }
if(isset($_GET['showtemplate'])) Debug::show($templates);
return new SSViewer($templates); return new SSViewer($templates);
} }

View File

@ -76,7 +76,9 @@ class RequestHandlingData extends ViewableData {
foreach($this->stat('url_handlers') as $rule => $action) { foreach($this->stat('url_handlers') as $rule => $action) {
if(isset($_REQUEST['debug_request'])) Debug::message("Testing '$rule' with '" . $request->remaining() . "' on $this->class"); if(isset($_REQUEST['debug_request'])) Debug::message("Testing '$rule' with '" . $request->remaining() . "' on $this->class");
if($params = $request->match($rule, true)) { if($params = $request->match($rule, true)) {
if(isset($_REQUEST['debug_request'])) Debug::message("Rule '$rule' matched to action '$action' on $this->class"); if(isset($_REQUEST['debug_request'])) {
Debug::message("Rule '$rule' matched to action '$action' on $this->class. Latest request params: " . var_export($request->latestParams(), true));
}
// Actions can reference URL parameters, eg, '$Action/$ID/$OtherID' => '$Action', // Actions can reference URL parameters, eg, '$Action/$ID/$OtherID' => '$Action',
if($action[0] == '$') $action = $params[substr($action,1)]; if($action[0] == '$') $action = $params[substr($action,1)];