> I have the following inside a Custom Tag:
>
> "session.#attributes.CartName#" = StructNew();
> "session.#attributes.CartName#.items = ArrayNew();
>
> Which seems to work fine, however if I try the following line:
>
> "session.#attributes.CartName#.items[1] = "blahblahblah";
> or
> <cfset "session.#attributes.CartName#.items[1]" = "blahblahblah">
>
> I get the following error:
>
> ---
> Cannot set dynamic variable with name
> 'session.myCart.items[1]'. The variable name is illegal.
> Variable names must start with a letter and can include only
> letters, numbers, and underscores.
> ---
>
> Obviously I am passing in the name 'myCart' as an attribute
> to the custom tag. Any ideas why it won't let me set any
> values in the array?
It won't because, well, it won't. I don't know if there's really a good
reason for that behavior. You could try using the SetVariable function
instead, although that probably won't work in this case either. However,
it's easy enough to work around that by taking advantage of the fact that CF
passes structures by reference, so you can have multiple names for a
structure, and they'll all point to the same actual thing.
<cfscript>
mystruct = StructNew();
mystruct.items = ArrayNew(1);
.. assign all your array values, etc ...
"Session.#Attributes.CartName#" = mystruct; // mystruct is being passed by
reference,
// and the new
name will keep it in scope
// beyond the
lifetime of the custom tag
</cfscript>
Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
voice: (202) 797-5496
fax: (202) 797-5444
______________________________________________________________________
Get Your Own Dedicated Windows 2000 Server
PIII 800 / 256 MB RAM / 40 GB HD / 20 GB MO/XFER
Instant Activation � $99/Month � Free Setup
http://www.pennyhost.com/redirect.cfm?adcode=coldfusionb
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists