Best Code Structure Technique

Discussion in 'PHP' started by FishSword, Jul 2, 2011.

  1. #1
    Hiya! ;),

    I've been thinking long and hard about the best way to structure the code for a project I'm currently working on, to allow for easy development and management.

    Upon carrying out a search on the internet relating to this subject, it has been mentioned more than once, that it is a good idea to separate presentation code from logic (e.g. HTML from PHP)

    I am keen to obtain a better understanding on how you guys would code a simple page that displays information from a database and requires some sort of user input, whilst allowing for error messages to be displayed, if the user incorrectly completes what was asked of them.

    Also, I'm currently looking into the best way to link different pages together within my application. I've checked out some forum software (phpBB, myBB and smf) for inspiration and they all tend to link to different pages of the website via a main index.php file, containing a switch statement. Is this the best way, or are there other techniques that could be used? - What are the advantages/disadvantages of this approach?

    Of course, choosing the best structure to use at the beginning of a project is highly important, as this will then need to be adopted throughout the application.

    If you could provide examples of code or point me in the right direction, it would be much appreciated.

    Many Thanks,

    FishSword
     
    FishSword, Jul 2, 2011 IP
  2. jazzcho

    jazzcho Peon

    Messages:
    326
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
  3. FishSword

    FishSword Active Member

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #3
    Hi Jazzcho,

    Thanks for your reply.

    What happens when you create a pagination script for example? You will then be mixing HTML with the PHP.
    Whilst looking at the "A very basic MVC example (WARNING - PHP Inside)" example shown on the website you provided the link for, how would you display any error messages to the user if the page asked for user input, and the user completed the fields incorrectly?

    Also, how would each of the pages be linked together? Using a switch statement in an index.php file? Is this the best solution, or can this be achieved some other way?

    Cheers for you help!

    Many Thanks,

    FishSword
     
    FishSword, Jul 3, 2011 IP
  4. amitavr

    amitavr Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    a very useful resource. thanks :)
     
    amitavr, Jul 4, 2011 IP
  5. ataaso

    ataaso Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    very nice :)
     
    ataaso, Jul 7, 2011 IP
  6. dsoft

    dsoft Greenhorn

    Messages:
    32
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #6
    thanks for the link jazzcho
     
    dsoft, Jul 9, 2011 IP