You are here: Re: PHP Beginner question « PHP Programming Language « IT news, forums, messages
Re: PHP Beginner question

Posted by David Haynes on 05/29/06 00:44

pepito3@gmail.com wrote:
> Hi. I have a question about PHP programming philosophy:
>
> Imagine a web of a shop with a table displaying the name of some
> products. There is a link "Buy" next to each product. I want that link
> to execute some PHP code, but I don't want the navigator to show
> another web.
>
> So imagine the file is product_list.php and the link is: <a
> href="add_product.php?code=...> Buy </a>. I want the code in
> add_product.php to be executed but I want the navigator to display the
> same page it is displaying at the moment (product_list.php or
> whatever).
>
> How can I do that?
>
> Thanks!
>

There are a number of ways of doing this, but the most common ones would be:
1. Have the page call itself and add the php code at the top of the page
to handle the order stuff.
2. Have the page call another php file that processes the form data and
then redirects to the calling form page again.

The first style has the benefit that all the code is in one place but
also has the problem that the amount of business logic code may obscure
the form code and that changing the look and feel of the form may be
difficult. Various 'tricks' with include() logic may help with this.

The second style separates the form (i.e. look and feel) from the
business logic by having a pre-defined set of private data that is
passed from the form to the business logic (via POST or GET) and from
the business logic to the form (via SESSION or GET). This separation is
often called the view (for the form piece) and the controller (for the
business logic piece). If you add a database or other data repository
(i.e. the data 'model'), then you are closer to implementing a full
model-view-controller (MVC2) implementation.

Both will work quite well. Choose the one that best suits your needs.

-david-

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация