/    Sign up×
Community /Pin to ProfileBookmark

effective navigation technique?

i have decided to change my navigation to a switch system.

is the below method an effective method of navigation or would it be better just to use an army of if/else if statements?

[code=php]
//page selection
if (empty($_GET[‘id’]))
{
require_once “includes/development.php”;
}
else
{
switch ($_GET[‘id’])
{
case 1:
$page = “development.php”;
break;
case 2:
$page = “about.php”;
break;
case 3:
$page = “articles.php”;
break;
case 4:
$page = “blog.php”;
break;
case 5:
$page = “portfolio.php”;
break;
case 6:
$page = “tutorials.php”;
break;
case 7:
$page = “login.php”;
break;
case 8:
$page = “members.php”;
break;
case 9:
$page = “iregister.php”;
break;
case 10:
$page = “contact.php”;
break;
case “admin”:
$page = “admin.php”;
break;
case “picture”:
$page = “img_upload_343.php”;
break;
case “verify”:
$page = “verification.php”;
break;
}
if (isset($page))
{
require_once “includes/”.$page;
}
else
{
require_once “includes/development.php”;
}
}[/code]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@bokehOct 22.2006 — Neither method is good. Each unique URL should lead to a file within the file system. Using a query string in this context is wrong. Query strings are for fetching data not opening files. Also instead of including the content into the template you should be including the template into the content.
Copy linkTweet thisAlerts:
@knowjauthorOct 22.2006 — index.php isn't actually my template page its just a controller page

[code=php]<?
require_once "/some file/sqlconnectionfile.php";
include_once 'includes/functions.php';
ob_start();
include "includes/header.php";

switch script for navigation/content management

include "includes/footer.php";
ob_end_flush();
?>[/code]



you will probably say that thats even worse but its just what i knew when i wrote the site
Copy linkTweet thisAlerts:
@pcthugOct 22.2006 — A previous client request that all data was stored within array variables, accessed via a [I]switch[/I] statement. There were 3 main sections of the app:

First there was the app controller ([I]index.php[/I]) which basically handled and served all requests.
[code=php]
<?php
/*
public.controller

*/
if(@ini_get('register_globals'))
foreach($_REQUEST as $name => $value)
unset($$name);

// make definitions, send headers and report errors
define('app_path', dirname(__FILE__));
define('tpl_file', app_path . '/template.tpl');

header('Content-type: text/html; charset=utf-8');

error_reporting(E_ALL);
@ini_set('display_errors', '1');

// build page parameter
$page = 'default';

if(isset($_GET['page']))
{
$page = strtolower(preg_replace('/([^a-z0-9_]+)/', '_', $_GET['page']));
$page = trim($page, '_');
}

// fetch relative data
@include app_path . '/_db.php';

// define template replacable objects
$search = array(
'content' => '<tpl:content>',
'keywords' => '<tpl:keywords>',
'title' => '<tpl:title>');

// sort arrays so they are aligned
ksort($search);
ksort($dat);

// output data filled template
echo str_replace($search, $dat, @file_get_contents(tpl_file));

?>[/code]

Next there was the application data ([I]_db.php[/I]) which basically returns a relative data array.
[code=php]
<?php
/*
public.data

*/
switch($page)
{
case 'default':

$dat['title'] = 'Welcome.';
$dat['keywords'] = 'Welcome, Default, Foobar';
$dat['content'] = 'Welcome to my website. This is the default page.';

break;

case 'about':

$dat['title'] = 'About';
$dat['keywords'] = 'About, Website, Hello World';
$dat['content'] = 'This is my About page...';

break;

case '404':
default :

$dat['title'] = 'Page not found.';
$dat['keywords'] = '404, Page Not Found, Oops';
$dat['content'] = 'Oops, page not found.';

}
?>[/code]

Finally we have our application template ([I]template.tpl[/I]) which serves as a template which is filled with data bfor being served to the user by our application controller.
[code=html]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<title><tpl:title></title>

<meta http-equiv="keywords" content="<tpl:keywords>">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

</head>

<body>
<p><tpl:content></p>
</body>
</html>
[/code]
×

Success!

Help @knowj spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...