Reply to Re: need a pointer on OOP with php

Your name:

Reply:


Posted by Henk Verhoeven on 08/07/06 22:21

nephish wrote:
> if i create a customer object when say, someone logs into the site. Can
> i pass that object to each page in session variables ? like from the
> login page, can the user move about the site without me coding the
> declarations over and over ?
>
> or is there a better way to go about this ?

Hi nephish,

Theoretically you store objects that should have the same lifetime or
shorter as the session in the session. Object that have a longer
lifetime, or have to be shared by multiple users you better store in in
a database. This is called 'persistency'. For more info on persistency
see
http://www-128.ibm.com/developerworks/opensource/library/os-php-flexobj/?ca=dgr-lnxw01DynamicPHP
http://www.onlamp.com/pub/a/php/2005/06/16/overloading.html
The thread "PHP Dynamic Database Code" started by josh.kuo@gmail.com on
Fri, 9 Jun 2006 23:13:21 +0000 (UTC) (from which i have the above urls)
may also be interesting.

Saving objects in the session in practice has often brougt me troubles.
The point is you must have its class loaded before the session is
started. This may be easy if you have only one page and one object
class, but i usually have many of both. In my experience it is more
reliable to copy all the objects member variables (but not the ones that
hold objects) into an asspciative array and store the array in the
session. When you later need the object you copy the values from the
array back into a new object.

Furthermore you could take a look at patterns. An example of a pattern
for user interfacing can be found at:
http://www.phppeanuts.org/site/index_php/Pagina/195
Many more patterns are at http://c2.com/cgi-bin/wiki?DesignPatterns
(if you get lost, try: http://c2.com/cgi-bin/wiki?search=controller )

Greetings,

Henk Verhoeven,
www.phpPeanuts.org.

Some OO terms and definitions:
http://www.phppeanuts.org/site/index_php/Menu/27/What+is.html
(contains interpretations specific to the phpPeanuts framework)

[Back to original 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

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