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

CFC Question

New Here ,
Oct 25, 2006 Oct 25, 2006

Copy link to clipboard

Copied

Hi,

I'm pretty new to CFCs and am re-working an application I made a while back. Basically, I have a User cfc and also a UserGateway cfc. When a user logs in, a User object is instantiated which stores their data in the session scope. However, if the user is an admin, they can also create or update users. In the update user form, another User object is instantiated with the selected user's properties. The question is, does this persist into the action page? Also, what if I do this multiple times. Does each instance need to be named something different? How long does the instatnce persist?

Thanks,
Frank
TOPICS
Advanced techniques

Views

236

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 ,
Oct 25, 2006 Oct 25, 2006

Copy link to clipboard

Copied

The question is, does this persist into the action page?

If you put the instanciated object into a variable scope that persists
such as session, application and server. Otherwise no it dies with all
other non-persistent variables of a request.


Also, what if I do this multiple times. Does each instance need to be
named something different?

Or put into different indexes of an array or structure so that a new
instant of the object does not overwrite a previous instant of the
object. YES.


How long does the instance persist?

Exactly as long as you define it to persist. Put it into short lived
scopes such as variables and request it lives only as long as the
current request. Put it into longer lived scopes such as session,
application and server, it lives as long as these scopes live.


Remember an instant of an object is just a very complex variable, but a
variable none the less and follows all the general rules of variables
simple or otherwise.

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
New Here ,
Oct 25, 2006 Oct 25, 2006

Copy link to clipboard

Copied

So if this is true, how do I update a user if I first have to instantiate the User object to load the "current" properties into the form? On the action page, do I have to create a new object and update it? Or if I put it into session, after the update, do I kill that object somehow? confused...

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 ,
Oct 25, 2006 Oct 25, 2006

Copy link to clipboard

Copied

LATEST
Normally You build a way in the component(aka object) that allows you to
update the data of the component. You can do this by making the
data(aka state or members) public and thus directly writable. Or, more
often considered the best practice, you would create methods(aka
functions) that accept parameters to update the data of the object.

One way this could be done.

In the CFC
----------
<cffunction name="setStatus" ...>
<cfargument name="statusValue" ...>
<!--- Do what needs to be done with the status value, if anything --->

<cfset variables.status = arguments.status>
</cffunction>

In the action
-------------
<cfset session.myUserObjVar.setStatus(form.newStatus)>


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