Difference between revisions of "PHP Programming tips"
Jump to navigation
Jump to search
Line 7: | Line 7: | ||
# It is a very good idea to use templates. | # It is a very good idea to use templates. | ||
# When having menus or things that will change often in a template, put them in different files and include those files in the template. This way it is easier to update a menu and to have more control. One way of using a template is shown in the table below: | # When having menus or things that will change often in a template, put them in different files and include those files in the template. This way it is easier to update a menu and to have more control. One way of using a template is shown in the table below: | ||
+ | {| border="1" cellpadding="0" | ||
+ | |+ Template Example | ||
+ | |- | ||
+ | |{{green|put logo here}} || {{red|Include Top Menufile here }} | ||
+ | |- | ||
+ | |{{red|Include Left Menu file here}} | ||
+ | | rowspan=5 valign="top" | {{blue|Editable region}} | ||
+ | |- | ||
+ | | | ||
+ | |- | ||
+ | | | ||
+ | |- | ||
+ | | | ||
+ | |- | ||
+ | | | ||
+ | |- | ||
+ | ! colspan="2" style="background:#ffdead;" | Put common non changing info here | ||
+ | |} | ||
+ | |||
+ | |||
# Use configuration files. Preferably keep those configs in a directory by themselves. | # Use configuration files. Preferably keep those configs in a directory by themselves. | ||
#* If one needs to make any changes to the site you are creating he/she should not have to change anything else in any other place except those files. | #* If one needs to make any changes to the site you are creating he/she should not have to change anything else in any other place except those files. |
Revision as of 08:50, 17 June 2005
The purpose of this page is to provide guidelines on php programming and in WEB- programming in general.
Using a good tool and knowing the capabilities of that tool will save you a lot of time and pain :). Most of the modern web-design tools can also provide you with common script language programming tools that can save you tons of time and frustration.
SO SPEND SOME TIME TO LEARN HOW TO USE the tool of your choice.
Things you should have in mind.
- It is a very good idea to use templates.
- When having menus or things that will change often in a template, put them in different files and include those files in the template. This way it is easier to update a menu and to have more control. One way of using a template is shown in the table below:
put logo here | Include Top Menufile here |
Include Left Menu file here | Editable region |
Put common non changing info here |
---|
- Use configuration files. Preferably keep those configs in a directory by themselves.
- If one needs to make any changes to the site you are creating he/she should not have to change anything else in any other place except those files.
- When there is a need for hostname usage, make sure there is no way to get the name automatically before hard coding it in. For example if you need the name of the hosting server, instead of typing it use the $_SERVER['HTTP_HOST'] variable.
- ALWAYS use relative paths instead of absolute. IF you must use absolute then you should put the put the common part in a variable and use that on the rest of the paths.
A good example is to use the $_SERVER['DOCUMENT_ROOT'] variable.
- Use a Cascading Style Sheet (CSS) file for manipulating all the colors and the looks of your site. This way you can very easily change the look and the touch of your site very easily.
- Reuse the code as much as possible. Instead of writing 5 times a JavaScript function that does similar things write it once in a file, and make it as generic as possible. Then include that file in all the pages you need it.