Jump to content

Coding Style


shaunie

Recommended Posts

Hi,

 

I use the following style for building my websites, I understand this is a fairly common style and was wondering if there is a name for it?

 

<?php
include ('application.php');
include ('cms_config.php');
include ('templates/header.php');

switch ($_GET['action']) {

	case "home" :
		display_home();
		break;

	case "services" :
		display_services();
		break;

	case "testimonials" :
		display_testimonials();
		break;

	case "contact" :
		display_contact();
		break;

	default :
		display_home();
		break;

}

include ('templates/footer.php');

// Function list

// Display home page
function display_home(){
	$qid = mysql_query('SELECT * FROM testimonials ORDER BY RAND() LIMIT 0,1;');
	include('templates/home.php');
}

// Display services page
function display_services(){
	include('templates/services.php');
}

// Display testimonials page
function display_testimonials(){
	$qid = mysql_query('SELECT * FROM Testimonials');
	include('templates/testimonials.php');
}

// Display home page
function display_contact(){
	include('templates/contact.php');
}

?>

Link to comment
Share on other sites

You can do this a little simpler and more modular like this:

$pages = array('home', 'services', 'testimonials', 'contact');

$page = isset($_GET['action']) ? $_GET['action'] : 'home';

$func = 'display_' . $page;

if (in_array($page, $pages) && function_exists($func)) {
$func();
} else {
echo 'page not found';
}

 

Link to comment
Share on other sites

Does this style match a common pattern / design?

 

The reason I ask is that I intend to outsource some of my basic programming tasks and would like to ensure the programmer is able to follow my way of doing things.

 

It is relatively common logic, but I'm not sure there is a specific name for it.

Link to comment
Share on other sites

Write it down very thoroughly how everything works and how future components should be structured. Any programmer should be able to commence working on the project after reading it.

 

Use the below document for inspiration, not copying since most will go beyond what you need, to create your own document:

http://www.cmcrossroads.com/bradapp/docs/sdd.html

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.