Forum OpenACS Development: Re: category map object

Collapse
2: Re: category map object (response to 1)
Posted by Ryan Gallimore on
Hi Iuri,

If I understand you correctly, just move the foreach containing

category::map_object -remove_old -object_id $video_id ${$cat_label}

inside your -on_submit block. Instead of ${$cat_label} type [set $cat_label].

Collapse
3: Re: category map object (response to 2)
Posted by Iuri Sampaio on
Ryan,

The problem is very basic, however a bit tricky: How to manipulate the name of the vars, in order to get them dynamically set. The category's ad_form elements have their names as cat_0356, cat_098 ...

That means 0356 is the category id and $cat_0356 is also a variable that contains the category of the child.

I am trying to deal with something like $cat_${category_id} but i get the following error bellow.

For example in the loop:

foreach {category_id category_name} [videos::get_categories -package_id $package_id] {
set tmp "$cat_${category_id}"
ns_log Notice "$tmp"

}

why doesn't $cat_${category_id} become $cat_0356 and moreover it does not write the value held in $cat_0356?

[04/Jun/2010:10:16:15][4386.3056024464][-default:0-] Error: POST http://192.168.6.35:8090/videos/videos-new?
referred by "http://192.168.6.35:8090/videos/videos-new?video_id=881";
can't read "cat_": no such variable
while executing
"set tmp "$cat_${category_id}""
("foreach" body line 2)
invoked from within
"foreach {category_id category_name} [videos::get_categories -package_id $package_id] {
set tmp "$cat_${category_id}"
ns_log Notice "$temp"

}"
("uplevel" body line 9)
invoked from within
"uplevel #$level $on_submit"
(procedure "ad_form" line 620)
invoked from within
"ad_form -extend -name video -form {
} -new_request {
set creator [videos::get_user_name -user_id [ad_conn user_id]]
set read_term 0
} -edit_re..."
("uplevel" body line 80)
invoked from within
"uplevel {
ad_page_contract {
This is a form to upload video

Collapse
4: Re: category map object (response to 3)
Posted by Dave Bauer on
You want to review how Tcl works http://philip.greenspun.com/tcl/

The answer is simple, there are many examples around the toolkit of dynamic variable names.

[set cat_${category_id}] will return the value of the variable you are looking for.

$cat_${category_id} is parsed as $cat_ $category_id since the parser does not do to passes.

NOTE that the index of an array is evaluated betfore the variable reference so $cat($category_id) will work where $cat_${category_id} will not.

Collapse
5: Re: category map object (response to 4)
Posted by Iuri Sampaio on
Thanks dave,

i tried to "read the manual" but it ended up i was just browsing the whole site looking for examples because i didn't know how do precisely call the problem i had in order to focus my research.

best wishes