matthewbonline — 2011-04-11T07:10:34-04:00 — #1
I know that CSS can define where things are on the page (layout). It can define header, left navigation, right navigation and footer and more.
But I know that PHP can be used to define the header, left navigation, right navigation and footer also.
I also know that PHP cannot help with layout issues and formatting of text, etc.
To what extent should I use PHP rather than CSS? Any guideline, or experienced developers have comments??
logic_earth — 2011-04-11T07:23:55-04:00 — #2
They are two different things. Do not even mix them up.
You cannot replace CSS with PHP no more then you can replace HTML with PHP.
lsc_rob — 2011-04-11T07:26:03-04:00 — #3
I think you may have missed the point of PHP a little...
CSS is purely for display - nothing more, nothing less.
PHP is a programming language, that can do - well just about anything really! From something as simple as a dynamic date, to 'including' files (such as your navigation), all the way up to complex calculations and functions (ecommerce systems, user profiles, anything your imagination can come up with).
In your example, you might have a PHP container page (index.php) with calls for your navigation, body, footer, etc. You would then use CSS to format the display of the page.
If you need any more clarification on anything, ask
matthewbonline — 2011-04-11T09:55:50-04:00 — #4
I am sure you understand that I could use the HTML and CSS I have for example for the homepage and save it as 4 separate files. Header, Footer, Left Navigation and Main info area in the remaining space on the page.
When I then use PHP to load these 4 files the code would be identical to what it was originally. All I have done is saved chunks of code to separate files. The argument for doing this is I only need to edit one of the PHP files for the changes to appear on all pages, which is logical and good practice.
However, I intend to design a template page, with links like www.mywebsite.co.uk/Products.php?id=1. So I will only have a small number of template files - Maybe even just 1! It seems less logical to break the code up for such a template. Would you forget about using PHP to include the separate chunks of code or not, when using a template?
alex__ — 2011-04-11T10:07:50-04:00 — #5
I would probably break up the template 'elements' e.g. header, footer, navigation into separate files for flexibility - and include these in the template - UNLESS you're sure you wouldn't need different headers/footers/etc for different pages.
You say you might only have one 'core' template file, this may change in future. Different template files may have different includes, and they may share some includes. The shared includes should each be maintained in a single file for obvious reasons.
Unless you know the scope of your application is always going to be very simple, why not make things as flexible as possible?
matthewbonline — 2011-04-11T10:44:34-04:00 — #6
In terms of the MySQL Database and PHP set-up what is the 'standard level' of information required at the web site? With plain HTML you have to write everything manually...but what should be my aim with PHP:
Just write the links and have everything generated using the 'get' function using the question mark in the URL? (Example: www.website.com/product.php?id=1)
Or is the 'standard' to go a step further and have the links generate themselves?
Or something else?
alex__ — 2011-04-11T12:20:46-04:00 — #7
I would definitely have a function or class to generate links within the application.
That way if your navigation structure ever changes e.g.
Then you won't have to manually rewrite all your links. Of course you can get Apache to rewrite the links automatically using mod_rewrite which is another option - but I'd certainly have some sort of link function either way.