Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"do it all" page structure and things to watch out for?

Tags:

php

structure

I'm still getting my feet wet in PHP (my 1st language) and I've reached the competency level where I can code one page that handles all sorts of different related requests. They generally have a structure like this:

(psuedo code)

<?php
include 'include/functions.php';
IF authorized

  IF submit (add data)
  ELSE IF update (update data)
  ELSE IF list (show special data)
  ELSE IF tab switch (show new area)
  ELSE display vanilla (show default)

ELSE "must be registered/logged-in"

?>
<HTML>
  // snip
  <?php echo $output; ?>
  // snip
</HTML>

and it all works nicely, and quite quickly which is cool. But I'm still sorta feeling my way in the dark... and would like some input from the pros regarding this type of page design...

  • is it a good long-term structure? (it seems easily expanded...)
  • are there security risks particular to this design?
  • are there corners I should avoid painting myself into?

Just curious about what lies ahead, really...

like image 439
Drew Avatar asked Dec 07 '25 06:12

Drew


1 Answers

This design is what starters go to when they advance a little bit. I went the same way having index.php being one big SWITCH statement calling the appropriate functions and templates based on the URL and parameters. This is very very basic step towards MVC design.

I suggest you to start expanding you knowledge in that direction. Reading more about what MVC (Model-View-Controller), how to create one and maintain it. Then you might be interested in experimenting with some MVC frameworks like CakePHP, CodeIgniter, Kohana...

Here are some articles for you:

What is MVC?

MVC for Noobs

CodeIgniter

like image 128
Ivo Sabev Avatar answered Dec 08 '25 19:12

Ivo Sabev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!