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

cfobject / cfinvoke problem in my application.cfc

Participant ,
Jun 03, 2009 Jun 03, 2009

Copy link to clipboard

Copied

Hello;

I am trying to use cfobject in my onsessionstart function in my application.cfc file. The cfobject is another application.cfc file I have in a sub directory in the web site, it runs the shopping cart. I am not firing this off properly and I was hoping someone could help me fix my code so it will operate properly.This is my invoke statement:

<cfobject name="SESSION.myShoppingCart" component="ShoppingCart">
<cfinvoke component="#SESSION.myShoppingCart#" method="getShoppingCart">

This is my whole argument statement for on session start:

<cffunction name="onSessionStart" returntype="any" output="true">
<cfset SESSION.created = now()> <!--- This sets off another session in the site --->
<cfobject name="SESSION.myShoppingCart" component="ShoppingCart">
<cfinvoke component="#SESSION.myShoppingCart#" method="getShoppingCart">

</cffunction>

this is my error:

Context validation error for tag cffunction.

The end tag </cffunction> encountered on line 80 at column 11 requires a matching start tag.
The error occurred in C:\website\Application.cfc: line 28
26 : <cffunction name="onSessionStart" returntype="any" output="true">
27 : <cfset SESSION.created = now()>
28 : <cfobject name="SESSION.myShoppingCart" component="ShoppingCart">
29 : <cfinvoke component="#SESSION.myShoppingCart#" method="getShoppingCart">

Can anyone help me? What do I need to do to set off my shopping cart functions on the cfc I am trying to invoke?

Thank You

CFmonger

TOPICS
Advanced techniques

Views

1.3K

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

correct answers 1 Correct answer

LEGEND , Jun 03, 2009 Jun 03, 2009

Your cfobject tag is fine.  It's the cfinvoke that is probably messing you up.

Once you have created an object from a cfc, you don't need to use the cfinvoke tag.  You call the methods like this.

<cfobject name = "AnObject" component = "SomeComponent>

<cfset SomeVariable = AnObject.AMethod(arguments go here)>

Votes

Translate

Translate
LEGEND ,
Jun 03, 2009 Jun 03, 2009

Copy link to clipboard

Copied

This looks wrong because session.myShoppingCart is not a component, it's a variable.

<cfobject name="SESSION.myShoppingCart" component="ShoppingCart">
<cfinvoke component="#SESSION.myShoppingCart#" method="getShoppingCart">

Next, your cfinvoke does not have a returnvariable.

None of this explains the missing start tag.  My guess is that it's a bonus error from your cfinvoke tag.

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
Participant ,
Jun 03, 2009 Jun 03, 2009

Copy link to clipboard

Copied

this is what I am supposed to put in the on sessionstart function:

<cfobject name="SESSION.myShoppingCart" component="ShoppingCart">

But this throws the same error. I am reading this off of instructions from a book. Obviously the book is wrong. Is there a way to make that cfobject statement work? I don't want a return variable. I want the ShoppingCart.cfc that resides in the sub directory /donation/ShoppingCart.cfc to go into client memory, I don't need a return value, I need the shoppong cart application portion fired when they hit the web site, creating a "shopping cart" in session / client variables.

How would I do that using this tag? Thanks.

CFmonger

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 ,
Jun 03, 2009 Jun 03, 2009

Copy link to clipboard

Copied

Your cfobject tag is fine.  It's the cfinvoke that is probably messing you up.

Once you have created an object from a cfc, you don't need to use the cfinvoke tag.  You call the methods like this.

<cfobject name = "AnObject" component = "SomeComponent>

<cfset SomeVariable = AnObject.AMethod(arguments go here)>

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
Participant ,
Jun 03, 2009 Jun 03, 2009

Copy link to clipboard

Copied

LATEST

That is what I am missing. The cfset tag.

Would I write the cfset like this?

<cfobject name="SESSION.myShoppingCart" component="ShoppingCart">

<cfset SESSION.myShoppingCart = ShoppingCart.get(arguments go here)>

what argument would I give it and is get the method I want? actually, is this correct at all?

CFmonger

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