Jump to content

All content in one page?


LooieENG

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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.