I feel that my current business view logic is not efficient or very clean. The problem is building the right output, but with less code and more DRY.
I have 3 'static' links, as in, direct tags:
about, contact, search
I also have three navigation menu's.
The first (URI position 1):
category = ['home', 'cat_1', 'cat_2', 'cat_3', 'cat_4', 'cat_5']
the second (URI position 2):
country = ['all', 'filter_1', 'filter_2', 'filter_3', 'filter_4', 'filter_5']
the third menu (URI position 3), is NOT on ever page, but only on pages that are not category 'home' AND not filter 'all'.
content = ['latest news', 'media and cartoons', 'country profile']
The third menu also does not use its last entry (profile) on any page whose filter is 'all'.
Possible page 'modes' are:
Home Page // 1 or 2 of the latest articles from all categories
URI: "/home/all/latest/"
List Page // list of latest 10 articles using category and filter for WHERE
URI: "/home/!all/latest/" OR "!home/(any)/latest/"
Article Page // full article
URI: "/(any)/(any)/article/"
About, Contact, Search page // simple pages
URI: "/about/", "/contact/", "/search/"
I am currently using URI position 1 to load a class of the same name as the URI string; validating if the class exists, and loading home page if it doesn't.
In the class that is instantiated by the URI Position, I have to validate and use if
else
statements to determine which of the above four page modes to load. As it stands now, that means I have about 9 pages that have a lot of repeating code:
CONTROLLER:
/** START page
* = build page elements using templates */
$page = new TemplateMan();
/** ADD content
* = add main page content to output */
$content_class = str_replace('-', '_', $this->breadcrumbs->getCrumb(1));
try {
if (!class_exists($content_class)) {
throw new Exception ('<b>Error - Content class is missing: ' . $content_class . '</b>');
}
$content = new $content_class($this->breadcrumbs, $this);
$content->setMainContent($inc_path);
} catch (Exception $e) {
echo
'<p><b>EXCEPTION</b><br />Message: '
. $e->getMessage()
. '<br />File: '
. $e->getFile()
. '<br />Line: '
. $e->getLine()
. '</p>';
}
$page->setDataValues('content', $content->getOutput());
/** RENDER page
* = render output to display page */
$page->buildOutput();
echo $page->renderOutput();
"home" class:
public function setMainContent($inc_path) {
/** ADD main content
* = add the main content to the output */
$array_helper = new ArrayHelp();
if ($array_helper->recValueReturn($this->breadcrumbs->getCrumb(3), $this->config->getNavThree())) {
switch ($this->breadcrumbs->getCrumb(3)) {
case 'latest':
if ($this->breadcrumbs->getCrumb(2) !== 'all') {
$this->output .= '<div>this is the list of articles page</div>';
} else {
$this->output .= '<div>this is the home page</div>';
}
break;
case 'media':
$this->output .= '<div>this is the media & cartoons page</div>';
break;
case 'country':
if ($this->breadcrumbs->getCrumb(2) !== 'all') {
$this->output .= '<div>this is the country profile page</div>';
}
break;
case 'article':
$this->output .= '<div>this is the article page</div>';
break;
default:
$this->output .= '<div>this is the default (home) page</div>';
break;
}
}
}
How can I make the logic better?
BTW: I have already come up with a different solution that works better since I posted this an hour ago, but I would really like to see what others would come up with.