You are here: Re: OOP database tables <-> php interface (semi LONG) « PHP Programming Language « IT news, forums, messages
Re: OOP database tables <-> php interface (semi LONG)

Posted by amygdala on 04/12/07 20:15

"Toby A Inkster" <usenet200703@tobyinkster.co.uk> schreef in bericht
news:jd61f4-4kp.ln1@ophelia.g5n.co.uk...
> amygdala wrote:
>
>> But the Validator class only checks each field seperately. In order to
>> keep
>> the Validator class as common as possible would you build a seperate
>> Login
>> class for instance? A class that has some custom validation methods? Or
>> perhaps just insert custom validation methods in the User class?
>
> class User
> {
> public static logon ($username, $password)
> {
> // Example query. You will want to protect against SQL
> // injection here.
> $q = "SELECT blah
> FROM blah
> WHERE username=$username
> AND password=$password";
> $result = run_query($q);
>
> if (!$result)
> return NULL;
>
> $user = new User;
> $user->load_data(/* blah */);
> return $user;
> }
> }
>
> This is an example of a User "factory". See "factory design pattern" in
> the
> PHP manual. To use it:
>
> $logged_in_user = User::logon($_POST['un'], $_POST['pw']);
> if (!$logged_in_user)
> echo "Login failed.";
>

Thanks for the response and the pointer.

I'm a little confused about the 'factory design pattern' though. Let me see
if I understand this correctly. Does the factory design pattern in this case
refer to the fact that you have different interfaces in one Class (in this
case class User) to create the object, depending on the purpose it serves.

So I could do a:

$blank_user = new User();

or I could do a

$logged_in_user = User::logon($_POST['un'], $_POST['pw']);

which both return a User object?

 

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

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