Welcome Guest, Not a member yet? Register   Sign In
The Controlller and Model same filename -> wrong ?
#19

[eluser]drewbee[/eluser]
Functions are built a little funkier in Cold Fusion, and there is no order to which you call parameters of a function. This one function below can be used strictly

Code:
<cffunction name="get_users" access="public" output="false" returntype="query">
    <cfargument name="account_id" required="false" type="numeric">
    <cfargument name="email" required="false" type="string">
    <cfargument name="name" required="false" type="string">
    <cfargument name="country" required="false" type="numeric">
    // Etc etc

    <cfquery name="local.query" datasource="#dsn#">
    SELECT *
    FROM accounts
    WHERE 0=0
    <cfif StructKeyExists(arguments, 'account_id')>
        AND account_id = #arguments.account_id#
    </cfif>
    <cfif StructKeyExists(arguments, 'email')>
        AND email = '#arguments.email#'
    </cfif>
    <cfif StructKeyExists(arguments, 'name')>
        AND name = '#arguments.name#'
    </cfif>
    <cfif StructKeyExists(arguments, 'country')>
        AND country = #arguments.country#
    </cfif>
    </cfquery>

    <cfreturn local.query />
</cffunction>

get all users
Code:
<cfinvoke method="get_users" returnvariable="users">

get user by id of 23
Code:
<cfinvoke method="get_users" account_id="23" returnvariable="users">

get user by account id of 23 and lives in USA (country code: 1)
Code:
<cfinvoke method="get_users" account_id="23" country="1" returnvariable="users">

get all users in the USA
Code:
<cfinvoke method="get_users" country="1" returnvariable="users">

As you can see one get method can be completely refactored into calling pretty much anything you need from the users table, whether it comes from building the query from lists of ids or really anything. It's the one thing I hate about C based languages, parameter lists in functions.


Messages In This Thread
The Controlller and Model same filename -> wrong ? - by El Forum - 04-08-2009, 03:48 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 04-08-2009, 04:04 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 04-08-2009, 04:21 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 04-08-2009, 06:30 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 04-08-2009, 06:39 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 04-08-2009, 06:54 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 04-08-2009, 07:04 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 04-08-2009, 07:10 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 04-08-2009, 07:25 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 04-08-2009, 08:24 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 04-08-2009, 09:13 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 05-10-2009, 01:42 PM
The Controlller and Model same filename -> wrong ? - by El Forum - 05-10-2009, 01:58 PM
The Controlller and Model same filename -> wrong ? - by El Forum - 05-10-2009, 02:15 PM
The Controlller and Model same filename -> wrong ? - by El Forum - 05-10-2009, 05:45 PM
The Controlller and Model same filename -> wrong ? - by El Forum - 05-11-2009, 01:38 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 05-11-2009, 07:51 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 05-11-2009, 08:10 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 05-11-2009, 08:33 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 05-11-2009, 08:45 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 05-11-2009, 08:55 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 05-11-2009, 09:04 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 05-11-2009, 09:14 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 05-11-2009, 09:26 AM
The Controlller and Model same filename -> wrong ? - by El Forum - 05-11-2009, 12:28 PM
The Controlller and Model same filename -> wrong ? - by El Forum - 05-11-2009, 01:19 PM
The Controlller and Model same filename -> wrong ? - by El Forum - 05-11-2009, 04:47 PM
The Controlller and Model same filename -> wrong ? - by El Forum - 05-12-2009, 10:11 AM



Theme © iAndrew 2016 - Forum software by © MyBB