Within our application we need to use the members first and last name within many pages. We have a profile.cfc handler that gets this data as a prc. How do I get access to that data from say pages within the project pages. I can do a dump of event and most of the data I need is there but I don’t know how to access it for display. I know this is easy, I’m just missing it???
Thank you so much,
Rick
Can you just store it in the session scope when they log in?
I have no idea what this means
I have a handler called profile.cfc and it has it’s own view. Profile.cfc gets the members first and last name and some other data. I also have a handler called Projects.cfc which needs the members first and last name. I tried to get it from the function in Profile.cfc so I wouldn’t have to duplicate it in the Project.cfc handler. I did a dump of the event, I guess it would be properties. It listed alot of functions and the data I need was also in the properties section of event, howver, I can’t seem to access it. I can dump everything in the public section but nothing in the properties, private or other area’s.
Sorry, I am a hack at best, just trying to get a prototype built and I keep running into these issues. I could put them in the session scope, that would likely be the smartest. I would still like to know how to get data into say my project file index.cfm that is retrieved from a different handler. I could do that under a different development structure, just haven’t figured it out with coldbox yet.
Thank you so much for your help!!!
In reality, there are many ways to do this. If you had an action (which is what we call methods in handlers) that got some data and put it in the prc
“scope”, and you wanted to re-use that logic elsewhere, you would run that event like
runEvent( 'profile.setMemberInfo' )
or whatever you called it from your projects.cfc.
I wouldn’t do it that way myself though. I would probably register an interceptor that runs on preProcess
which is before every request and detect if there is a logged in user and then set the prc
variables on any and every request automatically. Then they will be available anywhere in the site when the user is logged in. This has the least amount of duplicate code.
I have been looking forward to learning interceptors but have not gotten a full understanding on using or coding for them. What handler would you register the interceptor? Do you have a url that sort of shows how that could be done? Does this go in the main application.cfc?
Intereceptors can go in several places such as your config/Coldbox.cfc
, but generally they are a standalone CFC with a method named after the interception point you want to listen to. They are created by WireBox, so you can use property injection to access your models. Add the config in your main ColdBox config and they will get picked up and fired at the correct time.