tags:

views:

51

answers:

4

I am beginning to develop a website as a personal project, to discover a little bit web technologies. My question is more about "how to make the things clean" than a technical question.

Here is the thing:

Let's say that an index.php page will include an other menu.php, which will permit to navigate the website.

My index.php look like this, basically:

include("header");
include("menu");
include("DEPENDING ON WHICH LINK AS BEEN CLICKED FROM THE MENU");
include("bottom");

To avoid the POST method, and have a lot of stuff on my URL, I would like to do it an other way, but I do not know what is the best one.

I thought about declaring a variable like $page, when a link is clicked, I can do something like "if $page == home", then I include the home.php page... etc...

I do not know if my question is clear... I know that it will appear as a very easy and beginner question but I don't even know where to look...

Do you know if I can find any "open source website" so I can study the code and see the best practices about it?

P.S.: Sorry for my english which is probably not perfect at all, I am working on it.

+1  A: 

You can have a menu like

<a href="?view=home">Home</a>
<a href="?view=home">About</a>

Then on your PHP code

include $_GET["view"] . ".php";

Note that I am not validating, so any parameter passed on the url would be able to include any file.

The $_GET returns the values passed to the page through the URL.

The $_POST returns values posted.

The $_REQUEST returns both $_GET and $_POST values.

A good place to study many languages is W3Schools, you could check there sometime.

BrunoLM
What I would like to do is avoid having something like ?view=home on my url, I would like it to stay clean. But I don't know how to do that. My menu is a table with the href in it, so how can I refresh only the Center of my page, which will always contains the main content, regarding which link the visitor will click?
You want to load the page using ajax? This page http://orkutmanager.net/#v=home uses jQuery to add a handler on all `a` tags. The handler changes makes a ajax request and throws the result in the `#content` div. You can view the source to see how it's done... `function LoadPage(hash)`
BrunoLM
A: 

Make a page which will be common redirect page.

Every post will come to that page and based on the page parameter it will redirect.

So action of every page is same, but based on page paramter redirect to which ever page you want

You can switch case and

use header to redirect

i think you want to avoid GET method and avoid lot stuff in url

For learning

I thinks this is the simple website for learner.

http://www.w3schools.com/php/default.asp

http://www.plus2net.com/php_tutorial/site_map.php

http://www.tizag.com/phpT/

actually most of all these websites are same.

i hope you know the basic website PHP.net

Then,,.. no one is low level ..every low level will be in a top level one day.. just like you am also trying :)

zod
Thank you very much for your help and the docs :)
A: 

Hi you should please ask one question at a time:

I think this basic tutorial will give you a good idea on how and what to use the include(); func.

http://www.w3schools.com/php/php_includes.asp

I started with:

http://www.solitude.dk/filethingie/

Very simple .php file administrator.

You should definetly check out sourceforge, giant colletion of open source projects just filter by php (search for literally anything).

Just wanted to mention that you can download the full code of more complex pages (that are based on php) like

wordpress (blogging platform) - very easy to install and configure identi.ca (twitter open source alternave) You can now download reddit´s source code - quite easy to.

Maybe you wont be able to modify them immeditelly but theyll help you to get the picture

Trufa
A: 

Don't do what you are trying to do. The whole point of having pages is to handle things with different files. That is, you will have some commonality between files (handled by auto prepend and include path, potentially) such as your header and footer. Each file should include this on its own and print it out directly.

That is, you should not handle everything on one page and then conditionally include a file. Just send users to a different page.

Finally, I recommend not splitting up the header/footer files at all. Instead create a decorator that wraps the main content and displays it all at once. Something like:

$page = <<<HTML
<html><head><title></title></head>
<body>
   <div id="top nav"></div>
   {CONTENT}
</body>
</html>
HTML;

Then you go through and build your page content. Then you add it to CONTENT in the decorator and print it. PHPTAL is a great way to have this handled externally.

tandu
OK Thank you very much for your help.So as I understood, I should not split my header, bottom page and menu into different php files and then include them? Isn't it redundant ?Instead of that I will have my static index page I think, with only one section that will include a different page regarding where I am on the menu.Or should I do as much page as there are items on the menu, and have always everything static on every of them?
That is crazy! I don't know of any website that does what you are trying to do. How do you plan to effectively include the correct page each time without any significant problems?
tandu
What would you suggest? On the other hand, if I have 10 pages on my website, and if one day I want to make a change to the menu or on some other static stuff, I will have to do it for every page.
No! That is not the point I am suggesting at all! You may want to reread my post.. I am suggesting that you have a wrapper that has the top, the main menu and the bottom all at once and your page content gets put inside the wrapper. If you update the wrapper it will be on every page. I am saying don't separate the header/menu/footer and call the separately. Call them all at once.
tandu
OK I understand. I am sorry my english is not perfect at all, this is why I did not understand at the first time. Thank you!
I did what you said, thank you again for your help. After reflexion, it appears that it will be cleaner to do it this way. I will try to find how to inject the content between the brackets {CONTENT} as you explained to me. I don't know yet how to do that regarding the link the visitor is clicking on the menu.
I took a look at the design pattern Decorator, as you suggested, but as I understood it is more oriented for an OO based application, I don't really see how to use it here.
Doesn't have to be OO at all, you can do it functionally as well.
tandu