-
-
Save mhenke/540248 to your computer and use it in GitHub Desktop.
<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> |
<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> |
<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> |
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.
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.
I think everything between the new.cfm and edit.cfm is the same except the h1 tag. Then in the controller, there is four <cfset entry = model("Entry").findByKey(params.key)>. I think the reason is to keep the code simple and clear, allowing the person to implement what they want but I wanted your take.