Let's suppose that we want to execute a series of actions that does database
calls. Something like changing the access levels of users to a forum. For
this example, let us assume that the following variables are defined and being
passed in (by whatever method you want):
ModeratorIDList, a list of ids (unique person ids) for the users that will be
moderators for the forum
UserIDList, a list of all ids (unique person ids) for the users that have
access to the forum
thisForumID, the unique forum id for the forum that we are changing the
moderators and users for
Now I was taught that a fuse for database calls is simple and direct --
basically it does one action, an INSERT, UPDATE, or DELETE. However in this
example, I have to loop through the list variables (ModeratorIDList and
UserIDList) and apply the correct access level to each user specified in the
list variables.
Now using the fusebox and the model-view-control methodologies, what would be
the best way to execute this?
My answer, which is not 100% MVC (at least to my understanding of the MVC
methodology), is to use an action file to execute the database changes. How
can I do it? Below is my answer.
one action file that does this pseudo-code:
<!--- for each ModeratorID, add the record to the AccessTable --->
<cfloop list="#ModeratorIDList#" index="thisID">
<cfquery name="AddModerator_Insert" datasource="#dsn#">
INSERT INTO AccessTable (AccessID, UserID, ForumID,
AccessLevel)
VALUES (#MaxAccessID#, #thisID#,
#thisForumID#, #ModeratorAccessLevel#)
</cfquery>
<cfset MaxAccessID = MaxAccessID + 1>
</cfloop>
<!--- for each UserID, add the record to the AccessTable --->
<cfloop list="#UserIDList#" index="thisID">
<cfquery name="AddModerator_Insert" datasource="#dsn#">
INSERT INTO AccessTable (AccessID, UserID, ForumID,
AccessLevel)
VALUES (#MaxAccessID#, #thisID#,
#thisForumID#, UserAccessLevel#)
</cfquery>
<cfset MaxAccessID = MaxAccessID + 1>
</cfloop>
However, it seems to be that there ought to be a way to set fuseaction within
the action file, something like this:
<!--- for each ModeratorID, add the record to the AccessTable --->
<cfloop list="#ModeratorIDList#" index="thisID">
<!--- add call to db fuse to list of fuses to execute here --->
<cfset MaxAccessID = MaxAccessID + 1>
</cfloop>
<!--- for each UserID, add the record to the AccessTable --->
<cfloop list="#UserIDList#" index="thisID">
<!--- add call to db fuse to list of fuses to execute here --->
<cfset MaxAccessID = MaxAccessID + 1>
</cfloop>
I can even simplify this by defining the AccessLevel to be an input to the
procedure. But it still doesn't get me much closer to how to do this.
I suppose I could create a fuse in the model section that is simply the
function that does the database call. Then in the fuse that does the action,
call that function....
Is that the correct way to do it using the MVC methodology?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Discover CFTicket - The leading ColdFusion Help Desk and Trouble
Ticket application
http://www.houseoffusion.com/banners/view.cfm?bannerid=48
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:216370
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54