SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Evangelist
    Join Date
    Mar 2011
    Posts
    423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Moving from CSS to PHP

    Hi,

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

    Matthew.

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    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.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Enthusiast LSC-Rob's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, NSW Australia
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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
    Rob G.
    ShopManager - Sales & Repair Business Management Software

  4. #4
    SitePoint Evangelist
    Join Date
    Mar 2011
    Posts
    423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?


    Matt.

  5. #5
    SitePoint Member
    Join Date
    Nov 2008
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

  6. #6
    SitePoint Evangelist
    Join Date
    Mar 2011
    Posts
    423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

    Matt.

  7. #7
    SitePoint Member
    Join Date
    Nov 2008
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by MatthewBOnline View Post
    Or is the 'standard' to go a step further and have the links generate themselves?
    I would definitely have a function or class to generate links within the application.

    That way if your navigation structure ever changes e.g.

    from www.website.com/product.php?id=1
    to www.website.com/product/1

    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •