blesseld Posted June 4, 2009 Share Posted June 4, 2009 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. Link to comment https://forums.phpfreaks.com/topic/160936-using-a-case-to-store-variables-is-there-a-smarter-way/ Share on other sites More sharing options...
JonnoTheDev Posted June 4, 2009 Share Posted June 4, 2009 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']; ?> Link to comment https://forums.phpfreaks.com/topic/160936-using-a-case-to-store-variables-is-there-a-smarter-way/#findComment-849362 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.