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;
} else {
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();
global $_TEMPLATE_MANIFEST;
@ -49,22 +50,27 @@ class SSViewer extends Object {
else $templateFolder = null;
// 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);
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']);
}
// Use the theme template if available
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);
}
if($templateFolder) {
$this->chosenTemplates['main'] = $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);

View File

@ -105,7 +105,7 @@ class Controller extends RequestHandlingData {
$this->requestParams = $request->requestVars();
if(!$this->action) $this->action = 'index';
$methodName = $this->action;
// run & init are manually disabled, because they create infinite loops and other dodgy situations
if($this->checkAccessAction($this->action) && !in_array(strtolower($this->action), array('run', 'init'))) {
if($this->hasMethod($methodName)) {
@ -226,19 +226,22 @@ class Controller extends RequestHandlingData {
} else if($this->template) {
$templates = $this->template;
} else {
$parentClass = $this->class;
if($action && $action != 'index') {
$parentClass = $this->class;
while($parentClass != "Controller") {
$templates[] = strtok($parentClass,'_') . '_' . $action;
$parentClass = get_parent_class($parentClass);
}
}
$parentClass = $this->class;
while($parentClass != "Controller") {
$templateName = $parentClass;
if(($pos = strpos($templateName,'_')) !== false) $templateName = substr($templateName, 0, $pos);
if($action && $action != "index") $templates[] = $templateName . '_' . $action;
$templates[] = $templateName;
$templates[] = strtok($parentClass,'_');
$parentClass = get_parent_class($parentClass);
}
$templates = array_unique($templates);
}
if(isset($_GET['showtemplate'])) Debug::show($templates);
return new SSViewer($templates);
}

View File

@ -76,7 +76,9 @@ class RequestHandlingData extends ViewableData {
foreach($this->stat('url_handlers') as $rule => $action) {
if(isset($_REQUEST['debug_request'])) Debug::message("Testing '$rule' with '" . $request->remaining() . "' on $this->class");
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',
if($action[0] == '$') $action = $params[substr($action,1)];