shaunie Posted December 26, 2011 Share Posted December 26, 2011 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'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/253867-coding-style/ Share on other sites More sharing options...
scootstah Posted December 27, 2011 Share Posted December 27, 2011 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'; } Quote Link to comment https://forums.phpfreaks.com/topic/253867-coding-style/#findComment-1301494 Share on other sites More sharing options...
AGuyWithAthing Posted December 27, 2011 Share Posted December 27, 2011 Code indentation doesn't have a name but variable naming style does have a name such as Camel Case e.g. myVar. Quote Link to comment https://forums.phpfreaks.com/topic/253867-coding-style/#findComment-1301514 Share on other sites More sharing options...
shaunie Posted December 27, 2011 Author Share Posted December 27, 2011 Hi, Thanks for your replies, I actually meant they way I build the sites using templates and the structure of the php files, is this a common way to do it and does it have a name? I have seen it done like this in quite a few other places... Quote Link to comment https://forums.phpfreaks.com/topic/253867-coding-style/#findComment-1301580 Share on other sites More sharing options...
tecmeister Posted December 27, 2011 Share Posted December 27, 2011 There is know way of creating/programming a website. It is your own way. Some people may think its wrong/right. What ever way you feel comfortable with is fine. Quote Link to comment https://forums.phpfreaks.com/topic/253867-coding-style/#findComment-1301588 Share on other sites More sharing options...
scootstah Posted December 27, 2011 Share Posted December 27, 2011 There is know way of creating/programming a website. It is your own way. Some people may think its wrong/right. What ever way you feel comfortable with is fine. This isn't really true. There are plenty of common patterns and designs to use. Quote Link to comment https://forums.phpfreaks.com/topic/253867-coding-style/#findComment-1301589 Share on other sites More sharing options...
shaunie Posted December 28, 2011 Author Share Posted December 28, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/253867-coding-style/#findComment-1301712 Share on other sites More sharing options...
trq Posted December 28, 2011 Share Posted December 28, 2011 In some ways it is a very simplified MVC though you are mixing the Model into the Controller layer. Quote Link to comment https://forums.phpfreaks.com/topic/253867-coding-style/#findComment-1301716 Share on other sites More sharing options...
scootstah Posted December 28, 2011 Share Posted December 28, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/253867-coding-style/#findComment-1301724 Share on other sites More sharing options...
ignace Posted December 28, 2011 Share Posted December 28, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/253867-coding-style/#findComment-1301807 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.