4 Replies Latest reply on Aug 12, 2006 3:54 PM by Newsgroup_User

    Passing an argument with cfobject

    Level 7
      I am attempting to pass an argument to a cfc to get the results back to the
      calling page and am a wee bit confused.

      Here is my <cfobject>:
      <cfobject name="EditProject" component="sf_main.components.SingleProjects">
      <cfset myProject = EditProject.GetProject(project_id=#URL.project_id#)>

      I am attempting to pass the argument project_id to the cfc:

      <cffunction name="GetProject" access="remote" returntype="query">
      <cfargument name="project_id" type="numeric" required="true">
      <cfquery name="projects" datasource="#Request.MainDSN#">
      SELECT p.title, p.summary, p.duedate, c.company
      FROM project P LEFT OUTER JOIN client C ON p.client=c.username
      Where project_id=#argument.project_id# AND dirname='#Session.MM_Username#'
      </cfquery>
      <cfreturn projects>
      </cffunction>

      I keep getting and error saying that the argument "project_id" is undefined.
      What do I have to change on what to get it to pass correctly?

      Also, how do I pass multiple arguments to a cfc using this method?

      Thanks! I am just learning how to create and use CFCs, so bear with me. :-)

      --
      Wally Kolcz
      Developer / Support


        • 1. Re: Passing an argument with cfobject
          Level 7
          Ok, I thought I was getting smarter. I found you can use cfinvoke after a
          cfobject. I thought I could then use the cfinvokeagrument to pass the
          argument to the cfc, but it still fails.
          I have this now on my calling page:

          <cfobject name="EditProject" component="sf_main.components.SingleProjects">
          <CFINVOKE COMPONENT="#EditProject#" METHOD="GetProject"
          returnvariable="ProjectInfo">
          <cfinvokeargument name="project_id" value="#URL.project_id#">
          </cfinvoke>

          But it is still coming up with the error:

          Element PROJECT_ID is undefined in ARGUMENT.

          Any ideas or help?


          • 2. Re: Passing an argument with cfobject
            ksmith Level 1
            Try <cfset myProject = EditProject.GetProject(URL.project_id)> after your cfobject call.
            • 3. Re: Passing an argument with cfobject
              Dan Bracuk Level 5
              quote:

              Originally posted by: Newsgroup User
              I am attempting to pass an argument to a cfc to get the results back to the
              calling page and am a wee bit confused.
              Here is my <cfobject>:
              <cfobject name="EditProject" component="sf_main.components.SingleProjects">
              <cfset myProject = EditProject.GetProject(project_id=#URL.project_id#)>
              I am attempting to pass the argument project_id to the cfc:

              <cffunction name="GetProject" access="remote" returntype="query">
              <cfargument name="project_id" type="numeric" required="true">
              <cfquery name="projects" datasource="#Request.MainDSN#">
              SELECT p.title, p.summary, p.duedate, c.company
              FROM project P LEFT OUTER JOIN client C ON p.client=c.username
              Where project_id=#argument.project_id# AND dirname='#Session.MM_Username#'
              </cfquery>
              <cfreturn projects>
              </cffunction>

              I keep getting and error saying that the argument "project_id" is undefined.
              What do I have to change on what to get it to pass correctly?

              Also, how do I pass multiple arguments to a cfc using this method?

              Thanks! I am just learning how to create and use CFCs, so bear with me. :-)

              --
              Wally Kolcz
              Developer / Support




              You are so close. You only missed one letter.
              This
              Where project_id=#argument.project_id#
              should be this
              Where project_id=#argumentS.project_id#

              Plus, you made one other mistake. cfcs don't recognize the session scope, which leads to your next question:
              Also, how do I pass multiple arguments to a cfc using this method?

              There are at least two ways. You can use the cfinvokeargument tag or you can use the argumentcollection attribute of the cfinvoke tag. I prefer the latter.

              • 4. Re: Passing an argument with cfobject
                Level 7
                Thanks, that solved my problem.
                BTW a cfc can recognize a session. I use it all the time and it works fine.