Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Templates for namespaced controller classes #163

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 18 additions & 9 deletions control/Controller.php
Expand Up @@ -266,35 +266,44 @@ function getAction() {
*/ */
function getViewer($action) { function getViewer($action) {
// Hard-coded templates // Hard-coded templates
if($this->templates[$action]) { if ($this->templates[$action]) {
$templates = $this->templates[$action]; $templates = $this->templates[$action];
} else if($this->templates['index']) { } elseif ($this->templates['index']) {
$templates = $this->templates['index']; $templates = $this->templates['index'];
} else if($this->template) { } elseif ($this->template) {
$templates = $this->template; $templates = $this->template;
} else { } else {
// Add action-specific templates for inheritance chain // Add action-specific templates for inheritance chain
$parentClass = $this->class; $parentClass = $this->class;
if($action && $action != 'index') {
if ($action && $action != 'index') {
$parentClass = $this->class; $parentClass = $this->class;
while($parentClass != "Controller") {
$templates[] = strtok($parentClass,'_') . '_' . $action; while ($parentClass != 'Controller') {
$token = strtok($parentClass,'_');
$templates[] = str_replace('\\', '.', $token) . '_' . $action;
$templates[] = str_replace('\\', DIRECTORY_SEPARATOR, $token) . '_' . $action;
$parentClass = get_parent_class($parentClass); $parentClass = get_parent_class($parentClass);
} }
} }

// Add controller templates for inheritance chain // Add controller templates for inheritance chain
$parentClass = $this->class; $parentClass = $this->class;
while($parentClass != "Controller") {
$templates[] = strtok($parentClass,'_'); while ($parentClass != 'Controller') {
$token = strtok($parentClass,'_');
$templates[] = str_replace('\\', '.', $token);
$templates[] = str_replace('\\', DIRECTORY_SEPARATOR, $token);
$parentClass = get_parent_class($parentClass); $parentClass = get_parent_class($parentClass);
} }


// remove duplicates // remove duplicates
$templates = array_unique($templates); $templates = array_unique($templates);
} }

return new SSViewer($templates); return new SSViewer($templates);
} }

public function hasAction($action) { public function hasAction($action) {
return parent::hasAction($action) || $this->hasActionTemplate($action); return parent::hasAction($action) || $this->hasActionTemplate($action);
} }
Expand Down