Am 26.05.2009 um 20:08 schrieb Jeramy Wenserit:
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.
Yeah thats what I'm doing with the UserManagerModel :)
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.
My problem here was, that I didn't find a way to check the newly
create Doctrine_Record for its unique fields. I found a function in
Doctrine_Table::validateUniques which takes a Doctrine_Record as
argument, but I haven't been able to get the the Validation results.
as far as i understood the funtion the errors should be added to the
Doctrine_Record, but for some reasons there ain't any errors. So far I
did not get any answer from the Doctrine Developers how validation of
Unique fields can be one.
My conclusion was, to write a custom validator which uses the
UserManagerModel to query the DB for the Username and Email. It works,
but I would have preferred to user Doctrine itself for it ...
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.
Might you be able to gimme some example code, maybe even based on the
current Redracer Code, how I could use Action::validate*() for these
purposes?
I hope that's answered your questions,
Kind Regards,
Jeramy Wenserit (E_mE)
e: [email protected]
w: www.xylesoft.co.uk
Thanks for your response Jeramy
Benjamin
---
Dipl.-Betriebsw. (BA)
Benjamin Börngen-Schmidt
Pallaswiesenstraße 30
64293 Darmstadt
fon: +49 (0)6151 6795935
email: [email protected]
_______________________________________________
Agavi Dev Mailing List
[email protected]
http://lists.agavi.org/mailman/listinfo/dev