Created
August 20, 2010 13:01
-
-
Save mhenke/540248 to your computer and use it in GitHub Desktop.
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
<h1>Editing entry</h1> | |
<cfoutput> | |
#errorMessagesFor("entry")# | |
#startFormTag(action="update", key=params.key)# | |
#textField(objectName='entry', property='userID', label='User I D')# | |
#textField(objectName='entry', property='categoryID', label='Category I D')# | |
#textField(objectName='entry', property='title', label='Title')# | |
#textField(objectName='entry', property='body', label='Body')# | |
#dateTimeSelect(objectName='entry', property='dateCreated', dateOrder='year,month,day', monthDisplay='abbreviations', label='Date Created')# | |
#dateTimeSelect(objectName='entry', property='dateLastUpdated', dateOrder='year,month,day', monthDisplay='abbreviations', label='Date Last Updated')# | |
#submitTag()# | |
#endFormTag()# | |
#linkTo(text="Return to the listing", action="index")# | |
</cfoutput> |
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
<cfcomponent extends="Controller" output="false"> | |
# ... | |
<cffunction name="show"> | |
<!--- Find the record ---> | |
<cfset entry = model("Entry").findByKey(params.key)> | |
# ... | |
</cffunction> | |
<cffunction name="edit"> | |
<!--- Find the record ---> | |
<cfset entry = model("Entry").findByKey(params.key)> | |
# ... | |
</cffunction> | |
<cffunction name="update"> | |
<cfset entry = model("Entry").findByKey(params.key)> | |
# ... | |
</cffunction> | |
<cffunction name="delete"> | |
<cfset entry = model("Entry").findByKey(params.key)> | |
# ... | |
</cffunction> | |
</cfcomponent> |
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
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
<h1>Create new entry</h1> | |
<cfoutput> | |
#errorMessagesFor("entry")# | |
#startFormTag(action="create")# | |
#textField(objectName='entry', property='userID', label='User I D')# | |
#textField(objectName='entry', property='categoryID', label='Category I D')# | |
#textField(objectName='entry', property='title', label='Title')# | |
#textField(objectName='entry', property='body', label='Body')# | |
#dateTimeSelect(objectName='entry', property='dateCreated', dateOrder='year,month,day', monthDisplay='abbreviations', label='Date Created')# | |
#dateTimeSelect(objectName='entry', property='dateLastUpdated', dateOrder='year,month,day', monthDisplay='abbreviations', label='Date Last Updated')# | |
#submitTag()# | |
#endFormTag()# | |
#linkTo(text="Return to the listing", action="index")# | |
</cfoutput> |
Btw you are commenting out the difference between the actions ;) I could make any code duplicated if I remove the differences :P
Thanks, I'll add your justification to the article. Maybe you want to add that to the description so people if curious why all the duplication. They will understand why this isn't meant to be a final completely polished code generator.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Duplication in this case is more important than DRY. These templates are meant to display a barebone CRUD, while there is duplication, it can't be a crud if actions are missing (or "hidden" while using techniques to DRY up the code)
The templates are the exact same as Rails (back then, I don't know how they handle Scaffolding now), but the simplest the better, it is easier to "grasp" them as it is.