Re: Finding the value of a key in a nested structure
Cheers Ray - simple is good!! :) On 14 June 2010 17:02, Raymond Camden rcam...@gmail.com wrote: Evaluate is slow - comparatively. It isn't horrible though. The main reason I will complain about evaluate is when it isn't strictly necessary. Technically it isn't in your case. You could break up the string into parts and check the existence of each - but I think your code is fine (and a hell of a lot simpler). On Mon, Jun 14, 2010 at 9:44 AM, Tom King mailingli...@oxalto.co.uk wrote: nevermind - found the solution! ended up with: cffunction name=checkPermission cfargument name=path cfif IsDefined('session.currentUser.permissions.' arguments.path) cfif evaluate('session.currentUser.permissions.' arguments.path) cfreturn true cfelse cfreturn false /cfif cfelse cfreturn false /cfif /cffu ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:334568 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Finding the value of a key in a nested structure
Ok, my brain is hurting - I know this should be possible, but I can't quite get the syntax. I need to pass a string (a path to a structure which contains a boolean in the session scope) into a function, which then checks the value: i.e cfif checkPermission(email.send.all) Show a form or page /cfif cffunction name=checkPermission cfargument name=path cfif session.currentUser.permissions['#arguments.path#'] cfreturn true cfelse cfreturn false /cfif /cffunction So in this instance, CF is looking for session.currentUser.permissions['email.send.all'] - i.e a structure key name of 'email.send.all' , rather than session.currentUser.permissions.email.send.all Is there an elegant solution to this problem? Ta T ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:334528 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
RE: Finding the value of a key in a nested structure
When working with structures nested that deeply you might consider IsDefined instead. cfif IsDefined('session.currentUser.permissions.' arguments.path) It's not a best practice necessarily, but it would prevent a whole bunch of StructKeyExists calls. andy -Original Message- From: Tom King [mailto:mailingli...@oxalto.co.uk] Sent: Monday, June 14, 2010 9:20 AM To: cf-talk Subject: Finding the value of a key in a nested structure Ok, my brain is hurting - I know this should be possible, but I can't quite get the syntax. I need to pass a string (a path to a structure which contains a boolean in the session scope) into a function, which then checks the value: i.e cfif checkPermission(email.send.all) Show a form or page /cfif cffunction name=checkPermission cfargument name=path cfif session.currentUser.permissions['#arguments.path#'] cfreturn true cfelse cfreturn false /cfif /cffunction So in this instance, CF is looking for session.currentUser.permissions['email.send.all'] - i.e a structure key name of 'email.send.all' , rather than session.currentUser.permissions.email.send.all Is there an elegant solution to this problem? Ta T ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:334529 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: Finding the value of a key in a nested structure
Cheers Andy - That's fine if I want to check the struct exists, but I'm trying to directly test against the value of that path (which in this case is a boolean)...? T On 14 June 2010 15:25, Andy Matthews li...@commadelimited.com wrote: When working with structures nested that deeply you might consider IsDefined instead. cfif IsDefined('session.currentUser.permissions.' arguments.path) It's not a best practice necessarily, but it would prevent a whole bunch of StructKeyExists calls. andy -Original Message- From: Tom King [mailto:mailingli...@oxalto.co.uk] Sent: Monday, June 14, 2010 9:20 AM To: cf-talk Subject: Finding the value of a key in a nested structure Ok, my brain is hurting - I know this should be possible, but I can't quite get the syntax. I need to pass a string (a path to a structure which contains a boolean in the session scope) into a function, which then checks the value: i.e cfif checkPermission(email.send.all) Show a form or page /cfif cffunction name=checkPermission cfargument name=path cfif session.currentUser.permissions['#arguments.path#'] cfreturn true cfelse cfreturn false /cfif /cffunction So in this instance, CF is looking for session.currentUser.permissions['email.send.all'] - i.e a structure key name of 'email.send.all' , rather than session.currentUser.permissions.email.send.all Is there an elegant solution to this problem? Ta T ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:334530 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: Finding the value of a key in a nested structure
nevermind - found the solution! ended up with: cffunction name=checkPermission cfargument name=path cfif IsDefined('session.currentUser.permissions.' arguments.path) cfif evaluate('session.currentUser.permissions.' arguments.path) cfreturn true cfelse cfreturn false /cfif cfelse cfreturn false /cfif /cffunction (Never used evaluate() before, heard it was bad..?) T On 14 June 2010 15:29, Tom King mailingli...@oxalto.co.uk wrote: Cheers Andy - That's fine if I want to check the struct exists, but I'm trying to directly test against the value of that path (which in this case is a boolean)...? T On 14 June 2010 15:25, Andy Matthews li...@commadelimited.com wrote: When working with structures nested that deeply you might consider IsDefined instead. cfif IsDefined('session.currentUser.permissions.' arguments.path) It's not a best practice necessarily, but it would prevent a whole bunch of StructKeyExists calls. andy -Original Message- From: Tom King [mailto:mailingli...@oxalto.co.uk] Sent: Monday, June 14, 2010 9:20 AM To: cf-talk Subject: Finding the value of a key in a nested structure Ok, my brain is hurting - I know this should be possible, but I can't quite get the syntax. I need to pass a string (a path to a structure which contains a boolean in the session scope) into a function, which then checks the value: i.e cfif checkPermission(email.send.all) Show a form or page /cfif cffunction name=checkPermission cfargument name=path cfif session.currentUser.permissions['#arguments.path#'] cfreturn true cfelse cfreturn false /cfif /cffunction So in this instance, CF is looking for session.currentUser.permissions['email.send.all'] - i.e a structure key name of 'email.send.all' , rather than session.currentUser.permissions.email.send.all Is there an elegant solution to this problem? Ta T ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:334531 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: Finding the value of a key in a nested structure
Evaluate is slow - comparatively. It isn't horrible though. The main reason I will complain about evaluate is when it isn't strictly necessary. Technically it isn't in your case. You could break up the string into parts and check the existence of each - but I think your code is fine (and a hell of a lot simpler). On Mon, Jun 14, 2010 at 9:44 AM, Tom King mailingli...@oxalto.co.uk wrote: nevermind - found the solution! ended up with: cffunction name=checkPermission cfargument name=path cfif IsDefined('session.currentUser.permissions.' arguments.path) cfif evaluate('session.currentUser.permissions.' arguments.path) cfreturn true cfelse cfreturn false /cfif cfelse cfreturn false /cfif /cffu ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:334533 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm