Created
February 16, 2012 22:49
-
-
Save chrisdpeters/1848500 to your computer and use it in GitHub Desktop.
Script-Based Controllers and Models, Tag-Based Views
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component extends="Controller" { | |
/** | |
@hint Shows form for registering for social network. | |
*/ | |
public function register() { | |
user = model("user").new(); | |
} | |
/** | |
@hint Saves registration submission. | |
*/ | |
public function create() { | |
user = model("user").new(params.user); | |
user.save(); | |
if(user.hasErrors()) { | |
renderPage(action="register"); | |
} | |
else { | |
flashInsert(success="Thank you for registering for Social Network."); | |
redirectTo(controller="home"); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component extends="Model" { | |
/** | |
@hint Initializes associations and validations | |
*/ | |
public function init() { | |
// Associations | |
hasMany("chirps"); | |
// Validations | |
validatesPresenceOf("firstName,lastName,email,gender,urlId"); | |
validatesUniquenessOf("email,urlId"); | |
validatesLengthOf(properties="firstName,lastName", maximum=50); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfparam name="user"> | |
<cfoutput> | |
<h1>Register for Social Network</h1> | |
#startFormTag(action="create")# | |
#textField(label="First Name", objectName="user", property="firstName")# | |
#textField(label="Last Name", objectName="user", property="lastName")# | |
#textField(label="Email", objectName="user", property="email")# | |
<fieldset> | |
<legend>Gender</legend> | |
#radioButton(label="Male", objectName="user", property="gender", tagValue="M")# | |
#radioButton(label="Female", objectName="user", property="gender", tagValue="F")# | |
</fieldset> | |
<fieldset> | |
<legend>Profile Address</legend> | |
#textField(label="http://#cgi.script_name#/profile/", objectName="user", property="urlId")# | |
</fieldset> | |
<div> | |
#submitTag(value="Register Now")# | |
</div> | |
#endFormTag()# | |
</cfoutput> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment