开发者

Rules of thumb for separating parts of a web application

开发者 https://www.devze.com 2023-03-14 22:34 出处:网络
I am new to the world of web programming, have come up with some rules of thumb for the design of my first project. Do these sound like reasonable rules to go by, or should my code for various aspects

I am new to the world of web programming, have come up with some rules of thumb for the design of my first project. Do these sound like reasonable rules to go by, or should my code for various aspects of the project be more or less mixed together, or organized differently for some reason? Of the two books I've read relating to web programming (one on HTML & CSS, the other on PHP & MySQL), neither has clearly addressed this. Any opinions from experienced web developers will be greatly appreciated!

Rules of thumb:

  1. For relatively static content, use PHP to generate pages (i.e., fill in a news story) so HTML and PHP are mixed just a little here.

  2. For dynamic features, implement as an XML/plain text API so the PHP back end is not mixed in with any presentation logic (i.e., a server side API/service is implemented with no knowledge of presentation in it, then an AJAX client is de开发者_Python百科veloped and presented to the user)

  3. Determine how to break up AJAX client into different pages based on desire for user to be able to bookmark a page and navigate with browser.


See the MVC pattern for web applications. You don't need to resort to XML/plain text to separate presentation from logic. Using a PHP framework such as Symfony or Cake may help.

It may be best to develop a web application using HTML first and then sprinkle some AJAX on top so your application has a fallback if AJAX fails - e.g. mobile devices.

Hope that helps


You might want to investigate the MVC Pattern which is a great way to organize applications and separate the controller logic from the presentation logic.

Some popular PHP MVC frameworks include:

  • CakePHP
  • CodeIgniter

A more "difficult" framework (but the one I like the best), is Kohana

I would recommend starting with one of the first two.


Small, static sites: HTML only, or PHP with included header and footer, and common functions.

More complex: MVC framework that separates Views (templates) , Models (Database calls and data manipulation), and Controllers (Page routing)

AJAX: MVC framework on the backend, special page routes for getting page data (check for the right headers), history.pushState w/ hashbang backup for partial page loads. Depending on the complexity, perhaps having client-side templating.

0

精彩评论

暂无评论...
验证码 换一张
取 消