Jump to content

Using a Case to store variables... Is there a smarter way


blesseld

Recommended Posts

Hey All,

 

I am sure there is a smarter way of doing this...

Basically I have a file called control.php, and it contains a case.

 

for example on my index.php

 

I set a variable $sheet_name = "homepage"

and include my control.php

 

So every page on my site has "sheet name" I call it and set the other variables.  Reason I'm doing this is for quick editing for SEO, so I can edit titles and description and keywords for all my pages from one file.  I also set variables for different "categories" so I can highlight my navigation to show current page with a style if the category = "whatever"

 

	case 'homepage':
{
	$page_id = "1";
	$title ="Page Title";
	$meta_desc = "Page Description";
	$meta_key = "keywords";
	$category = "keywords";
	  include("inc/head.php");
	  include("inc/header1.php");
	break; 
}

 

basically, Is this at all a smart way of doing this or should I move to storing variables in a database and then calling them?  Or continue with how I have it.

If it is only you updating then it may aswell be in a static file unless you start to add many more pages then a database is the best bet. If static I think I would have used an array with the page id as the key:

<?php

$pages[1] = array('title' => 'home', 'meta_key' => '', 'meta_desc' => '');
$pages[2] = array('title' => 'about', 'meta_key' => '', 'meta_desc' => '');
$pages[3] = array('title' => 'contact us', 'meta_key' => '', 'meta_desc' => '');

// get page details - if page_id parameter is not set or invalid then set to 1	
$thisPage = $pages[(array_key_exists($_GET['page_id'], $pages) ? $_GET['page_id'] : 1)];
print $thisPage['title'];
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.