Hi Benjamin,
I've finished quite a lot of the User stuff for the Redracer Project
(not yet commited). But while I was writing the register action I hit
a problem on which I would like to here some comments.
When a new user registers of course he cannot use a username or email
which is already used by some other user (you'll be able to login via
username or email). Of course I can create unique indexes in the DB
and handle the Exception. But this would make the action very
dependend on a specific library, in my case Doctrine.
Use Agavi Model's to create a wrapper around your Doctrine user
object, so if in the future you want to move to a different ORM/
Database methodology, it will create a minimal affect the agavi
implementation as you only need to replace the Doctrine and adjust
your Model methods accordingly and bravo the Agavi actions/views/
validators/etc should be untouched.
My next thought was "Write a custom validator which checks if either
username or email is already used)
Since I have two global models (UserManager, User) whereas the
UserManager handles all interations with the DB, custom validator
could use the model to determine wether username and/or email is
already used.
You should use this method for validating user details, or if you feel
that creating a custom validator for only one purpose is a little over
the top, attempt using Action::validate*() instead.
For me the second approch seems to be more "Agavi like", but maybe
there is a thrid way to achieve this.
Also since I'm a newbie to doctrine, maybe doctrine has a way to
validate/test which field would not meet the unique attribute anymore
if the new record would be inserted. Currently I'm doing $user-
>save(); and then I get the exception if uniqueness is broken.
Personally, I would suggest against using an `Exception` for such
behaviour, exceptions should be used to notify the programmer of
possible internal problems, not for standard error management. You
should instead use a Agavi `Model` method which talks to Doctrine for
the checking of the e-mail addresses or what not; which would then
return a boolean value.
Then you can use this `Model` method in you custom validator or
Action::validate*() method, or even in other methods that require
similar checking.
I hope that's answered your questions,
Kind Regards,
Jeramy Wenserit (E_mE)
e: [email protected]
w: www.xylesoft.co.uk
_______________________________________________
Agavi Dev Mailing List
[email protected]
http://lists.agavi.org/mailman/listinfo/dev