Welcome Guest, Not a member yet? Register   Sign In
[In the Works] Datamapper ORM Class
#2

[eluser]Michael Wales[/eluser]
We also created a new user from our signup form. That form looks like:
Code:
<form method="post" action="signup" name="signup" id="signup"><!-- Note: This doesn't matter -->
<p>Username:<br />
&lt;input type="text" name="signup[username]" id="signup_username" maxlength="20" /&gt;&lt;/p>
<p>Password:<br />
&lt;input type="password" name="signup[password]" id="signup_password" maxlength="20" /&gt;&lt;/p>
<p>Email Address:<br />
&lt;input type="email" name="signup[email]" id="signup_email" maxlength="120" /&gt;&lt;/p>
<p>&lt;input type="submit" name="signup[submit]" value="Signup" /&gt;&lt;/p>
&lt;/form&gt;

The magic happens because of how we named all of our input fields (not id - just the name parameter). We can now use the fromForm() method to easily pull all these values down into our model, validate them against our rules, and save them to the database. Remember how we didn't add any validation rules for fields like salt? That means no matter if a user changes your form to add in a salt field - it's not going anywhere near your database. All, without any real work on your behalf.

Finally we updated a user's information. You'll be glad to know that Datamapper doesn't just issue a wide-open UPDATE statement to the database - that would be to simple. Datamapper is optimized to the gills and will only issue updates for fields that actually change.


Messages In This Thread
[In the Works] Datamapper ORM Class - by El Forum - 08-27-2008, 06:50 AM
[In the Works] Datamapper ORM Class - by El Forum - 08-27-2008, 06:56 AM
[In the Works] Datamapper ORM Class - by El Forum - 08-27-2008, 07:26 AM
[In the Works] Datamapper ORM Class - by El Forum - 08-27-2008, 07:31 AM
[In the Works] Datamapper ORM Class - by El Forum - 08-27-2008, 07:36 AM
[In the Works] Datamapper ORM Class - by El Forum - 08-27-2008, 09:00 AM
[In the Works] Datamapper ORM Class - by El Forum - 08-27-2008, 09:31 AM
[In the Works] Datamapper ORM Class - by El Forum - 08-27-2008, 09:34 AM
[In the Works] Datamapper ORM Class - by El Forum - 08-28-2008, 02:10 AM
[In the Works] Datamapper ORM Class - by El Forum - 08-28-2008, 09:52 AM
[In the Works] Datamapper ORM Class - by El Forum - 08-28-2008, 12:32 PM
[In the Works] Datamapper ORM Class - by El Forum - 08-28-2008, 01:03 PM
[In the Works] Datamapper ORM Class - by El Forum - 08-28-2008, 09:13 PM
[In the Works] Datamapper ORM Class - by El Forum - 08-29-2008, 04:27 AM
[In the Works] Datamapper ORM Class - by El Forum - 08-29-2008, 04:37 AM
[In the Works] Datamapper ORM Class - by El Forum - 08-29-2008, 06:25 AM
[In the Works] Datamapper ORM Class - by El Forum - 08-29-2008, 06:59 PM
[In the Works] Datamapper ORM Class - by El Forum - 08-30-2008, 08:09 AM
[In the Works] Datamapper ORM Class - by El Forum - 09-01-2008, 06:24 AM
[In the Works] Datamapper ORM Class - by El Forum - 09-01-2008, 08:11 AM
[In the Works] Datamapper ORM Class - by El Forum - 10-21-2008, 06:25 PM
[In the Works] Datamapper ORM Class - by El Forum - 10-30-2008, 01:44 PM
[In the Works] Datamapper ORM Class - by El Forum - 10-30-2008, 01:46 PM



Theme © iAndrew 2016 - Forum software by © MyBB