|
Posted by Jerry Stuckle on 06/22/07 12:06
Phil Latio wrote:
> I am designing a relatively simple CMS with the usual Item, Category and
> User scenario. My question here relates to how I implement the User
> registration on this application. Currently I have the following:
>
> register.php
> classes/class.Form.php
> classes/class.Validation.php
> classes/class.User.php
> classes/class.MySQL.php
> templates/register.tpl.php
>
> The thing that is really bugging me is how I perform the validation on what
> is entered on the register.php page?
>
> My first version (which I actually coded) simply created a new instance of
> the Validation class on the register.php page then performed numerous if
> statements with an error increment counter and if that returns zero (once
> all the tests are completed) then proceed else redisplay registration.php
> page. Works OK but looks terribly ugly and I am convinced there are far
> better approaches.
>
> My second idea is to use CRUD methods within the User class and have the
> User class call the validation directly.
>
> My third idea was to somehow apply the validation rules to the form objects.
> I have seen that some frameworks use this method but my problem is that I am
> really bad at understanding other people's code.
>
> I keep hearing the term "design patterns" and just wondering if reading a
> book or two on that subject might clear my head on how to progress forward.
> The problem is not that I cannot code this, it's the approach I should take
> and would value some opinions by the piers of the group.
>
> Cheers
>
> Phil
>
>
Phil,
Class objects should validate themselves - they shouldn't have to rely
on outside code. So in your case I would suggest validating in the user
class.
Also, beware - your "validation" class is probably not an appropriate
class. Does it have its own members (which aren't members of other
classes)? Or is it just validating some other class? If the former, it
would be a valid class. However, it's easy to fall into a trap of the
latter. In that case it should be a method, not an object.
It's easy to get confused, especially when you get something like
"validate" (a verb) and "validation" (a noun). One is a method, one is
a classes.
And btw - "display" is even worse! :-)
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
[Back to original message]
|