LooieENG Posted June 3, 2008 Share Posted June 3, 2008 Is this a good idea, or a bit pointless? I mean having something like <?php if ( $_GET['page'] == 'home' ) { // home page } if ( $_GET['page'] == 'page2' ) { // Load page 2 } ?> And then the tabs would be index.php?page=home Or is it better to use different pages? Quote Link to comment https://forums.phpfreaks.com/topic/108549-all-content-in-one-page/ Share on other sites More sharing options...
redbullmarky Posted June 3, 2008 Share Posted June 3, 2008 having everything feed through one single script is my own way of doing things, as it makes cross-site updates much easier - ie, just adding an include to one single file to affect the entire site, etc. however i wouldn't recommend you put all your code in one page, but rather include in the files and keep specific page code in their own files. might be worth taking a look at a framework to see how they go about it - CakePHP, Zend, CodeIgniter et al all operate in this sort of manner. Quote Link to comment https://forums.phpfreaks.com/topic/108549-all-content-in-one-page/#findComment-556605 Share on other sites More sharing options...
hansford Posted June 3, 2008 Share Posted June 3, 2008 I like using an index page to process all pages. The index will have your site map, menu, header, footer etc.. and then include('page2') etc.. so the answer to your question is no - its not pointless - it's smart web development. Of course a better idea is using a template based system-ie: CMS -the idea being that we want to seperate code from html and other design processes. The designers can do their thing and not mess up our code and we can do our thing and not have to sift through all of that CSS and HTML and figure out where to place our code. Quote Link to comment https://forums.phpfreaks.com/topic/108549-all-content-in-one-page/#findComment-556624 Share on other sites More sharing options...
LooieENG Posted June 3, 2008 Author Share Posted June 3, 2008 I mean like this http://ehwtf.com/a.php <?php if ( $_GET['page'] == 1 ) { ?> <h3>Page 1</h3> <p>Page 1 stuffs.</p> <?php } if ( $_GET['page'] == 2 ) { ?> <h3>Page 2</h3> <p>Page 2 stuffs.</p> <?php } ?> <p><a href="a.php?page=1">Page 1</a> | <a href="a.php?page=2">Page 2</a></p> Quote Link to comment https://forums.phpfreaks.com/topic/108549-all-content-in-one-page/#findComment-556920 Share on other sites More sharing options...
redbullmarky Posted June 3, 2008 Share Posted June 3, 2008 messy. the advice given before is sort of achieving the same thing in a similar way, just far more maintainable. using opening/closing tags left, right and center in this way will just confuse you and whoever else has to maybe deal with your code in the future. your example has just a few basic lines. imagine sneaking an entire webpage in there, and then trying to navigate around your code page to find certain pages to make amendments.... Quote Link to comment https://forums.phpfreaks.com/topic/108549-all-content-in-one-page/#findComment-556963 Share on other sites More sharing options...
LooieENG Posted June 3, 2008 Author Share Posted June 3, 2008 So multiple pages would be better? Quote Link to comment https://forums.phpfreaks.com/topic/108549-all-content-in-one-page/#findComment-556974 Share on other sites More sharing options...
hansford Posted June 4, 2008 Share Posted June 4, 2008 This type of code would be inside index.php ----------------------------------------- include('header.php') if(isset($_GET['page'])){ switch($_GET['page']){ case 1 : include('page1.php'); break; case 2 : include('page2.php'); break; case 3 : include('page3.php'); break; default: include('main.php'); } else{ include('main.php'); } } include(footer.php); Quote Link to comment https://forums.phpfreaks.com/topic/108549-all-content-in-one-page/#findComment-557056 Share on other sites More sharing options...
redbullmarky Posted June 4, 2008 Share Posted June 4, 2008 So multiple pages would be better? i suppose in a way, you could say that you're using multiple pages in that each page has their own file. the difference being in the implementation - instead of using files and directories and calling the file straight from the URL, you set your server up to "funnel" everything through one single index file, and include the page-specific content as required based on the URL parameters. Quote Link to comment https://forums.phpfreaks.com/topic/108549-all-content-in-one-page/#findComment-557213 Share on other sites More sharing options...
tmallen Posted June 4, 2008 Share Posted June 4, 2008 This type of code would be inside index.php ----------------------------------------- include('header.php') if(isset($_GET['page'])){ switch($_GET['page']){ case 1 : include('page1.php'); break; case 2 : include('page2.php'); break; case 3 : include('page3.php'); break; default: include('main.php'); } else{ include('main.php'); } } include(footer.php); I think that this is a better method, correct me if I'm wrong: <?php if (isset($_GET['id'])) { $page = 'page' . $_GET['id'] . '.php'; if (!include_once $page) { include_once 'main.php'; } } Not sure about include_once's return value, and I haven't tested it locally. Give it a try though. And this is just for arguments sake; there are much better ways to do this I'm sure. Quote Link to comment https://forums.phpfreaks.com/topic/108549-all-content-in-one-page/#findComment-557807 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.