• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Passing an argument with cfobject

LEGEND ,
Aug 10, 2006 Aug 10, 2006

Copy link to clipboard

Copied

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


TOPICS
Advanced techniques

Views

599

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 10, 2006 Aug 10, 2006

Copy link to clipboard

Copied

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?


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 11, 2006 Aug 11, 2006

Copy link to clipboard

Copied

Try <cfset myProject = EditProject.GetProject(URL.project_id)> after your cfobject call.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 11, 2006 Aug 11, 2006

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 12, 2006 Aug 12, 2006

Copy link to clipboard

Copied

LATEST
Thanks, that solved my problem.
BTW a cfc can recognize a session. I use it all the time and it works fine.


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation