views:

40

answers:

1

Hi, looking for best practices in web development, when you are writing a web application in a traditional non-framework environment (core PHP or Perl / CGI), what is the cleanest way to organize or map calls from the client to server processes?

The answer is rather trivial when working in a single-scope page where, for example, you have a form to complete and a submit button. You could set the action of the form to "save.php" and have a one-to-one relation between the page and the function it is bound to. So save.php could execute the save action and write to the client the form.

Now, the only non out-of-the-box php enhancement i'm using is a template engine (tinybutstrong). Whenever i have a complex page with multiple forms (for example, for sorting a grid, saving something, requesting something else, an ajax component and a search box), what is your way to lay down the various functions (search, sort, insert, retrieve) to a single display page (index)?

Do you use something like index.php?action=search / index.php?action=insert or something like setting each action to a page that acts like a function (search.php, sort.php, insert.php) each delegating the presentational function to a single script (index.php)? What if the "search" function can be used by varius "views"?

I'm using general terms like search or insert as an example, and the referece to PHP is also only for example, as I think my question is rather general on best practices. Thanks.

A: 

By creating something where there's an action which refers you to a view, you're essentially creating a controller for views, and you're two thirds of the way to MVC. (not that there's anything wrong with that, just that's where you're headed)

Q1. what is the cleanest way to organize or map calls from the client to server processes?

A1. Using the filesystem, but structured semantically based on the structure of your data (if possible) doing something like /search/mysearch is your semantically correct option. Requires a little Apache Mojo

Q1. Do you use something like index.php...

A1. Yes, I wouldn't shy away from this approach. It's ideal to use a little Apache rewrite magic to create nice paths, but aside from that, there isn't any other magic way to create an controller.

altCognito