SES name-value pairs howto recover them?

Hi!

I'm using coldbox 2.6.3. With SES enabled with the default routes:
<cfset addCourse(":handler/:action/:id")>
<cfset addCourse(":handler/:action")>
<cfset addCourse(":handler")>

I'm trying to pass on some variables with the link:
http://myserver/myapp/index.cfm/handler/action/variable_name/variable_value

But I can't find a way to retrieve the value. In the view, the
variable rc.variable_name is undefined.

What am I doing wrong? How can I retrieve that value?

Thanks!

Pedro.

Pedro,

that is because of the course:
<cfset addCourse(":handler/:action/:id")>

The variable value is coming as id and the other one is lost. Remove this course, as it is no longer necessary. THen you will see what you want.

Is "RC.id" defined and does it equal "variable_name"? That'd mean the
first rule was matching.

If the variable name is not important in the url, you could use a url
like the one below and then reference "RC.id" as the "variable_name".

http://myserver/myapp/index.cfm/handler/action/variable_value

- Gabriel

Hi Luis,

Thanks for your help... and for the great framework. It's a real
timesaver!

Great work!

Pedro.

The topic has changed to SOLVED, but what was the solution?

I have the same problem. I am using coldbox 2.6.3. With SES enabled
with the default route:

<cfset addCourse(":handler/:action?/:id?")>

and use package/handler/action/87 in a href OR the address field it
works but I have to change code in my handlers. To make it work I have
to change my Event.getValue("bannerId","") to Event.getValue("Id","")

IT WORKS, but it is not good.

Then if I try: (as Luis suggest: "The variable value is coming as id
and the other one is lost. Remove this
course, as it is no longer necessary. THen you will see what you
want".):

<cfset addCourse(":handler/:action")>
<cfset addCourse(":handler")>

Then it does not work, no id in the request scoope only the event:
{event={admin.ehBanner.dspBanner}}

I must have done something right because the first works but obvious I
do not have any name-value pairs by convention in the rc. Could it be
some settings that is not mentioned in the Guides?

I have read the SES Guide and have also tried addRoute
(':handler/:action') (in the routes.cfm I asume?). but then I got the
error that the method does not exist (!)

Under the paragraph "Convention name-value pairs" I read:

ColdBox introduces name-value pairs by convention by inspecting the
incoming URL. This means that after a route has been matched and there
are still values in the request string, the interceptor will try to
create name-value pairs out of them. Example, if we have the following
route:
addRoute(':handler/:action')

Then if we have the following url: index.cfm/users/list/page/2/issues/
5 Then the interceptor would route it to the event = users.list and
nothing more. With convention name-value pairs, the interceptor will
try to create name-value pairs from the remaining string, in our case:
page/2/issues/5. So the interceptor will create the following
variables in the request collection for you, without YOU doing
anything:
page = 2
issues = 5

So my question is how do I activate this magic behavior?

I have also updated the buildLink to accept querys as argument:
event.buildLink('admin.ehBanner.dspBanner',True,False,' ' ,'bannerid =
#bannerId#')

Hmm, I had deactivated the magic behaviour by changing the Build Link:
event.buildLink('admin.ehBanner.dspBanner',True,False,'
' ,'#bannerId#')
This worked with <cfset addCourse(":handler/:action?/:id?")> but not
with the right solution.. Puh. I think it´s solved for me to :-).

But I still wonder what addRoute is..

Answers below:

The topic has changed to SOLVED, but what was the solution?

I have the same problem. I am using coldbox 2.6.3. With SES enabled
with the default route:

<cfset addCourse(":handler/:action?/:id?")>

and use package/handler/action/87 in a href OR the address field it
works but I have to change code in my handlers. To make it work I have
to change my Event.getValue(“bannerId”,"") to Event.getValue(“Id”,"")

IT WORKS, but it is not good.

Then if I try: (as Luis suggest: “The variable value is coming as id
and the other one is lost. Remove this
course, as it is no longer necessary. THen you will see what you
want”.):

<cfset addCourse(":handler/:action")>
<cfset addCourse(":handler")>

Then it does not work, no id in the request scoope only the event:
{event={admin.ehBanner.dspBanner}}

I must have done something right because the first works but obvious I
do not have any name-value pairs by convention in the rc. Could it be
some settings that is not mentioned in the Guides?

I have read the SES Guide and have also tried addRoute
(’:handler/:action’) (in the routes.cfm I asume?). but then I got the
error that the method does not exist (!)

addRoute is for coldbox 3.0, before is addCourse

Under the paragraph “Convention name-value pairs” I read:

ColdBox introduces name-value pairs by convention by inspecting the
incoming URL. This means that after a route has been matched and there
are still values in the request string, the interceptor will try to
create name-value pairs out of them. Example, if we have the following
route:
addRoute(’:handler/:action’)

Then if we have the following url: index.cfm/users/list/page/2/issues/
5 Then the interceptor would route it to the event = users.list and
nothing more. With convention name-value pairs, the interceptor will
try to create name-value pairs from the remaining string, in our case:
page/2/issues/5. So the interceptor will create the following
variables in the request collection for you, without YOU doing
anything:
page = 2
issues = 5

So my question is how do I activate this magic behavior?

You don’t need to activate it, it does it automatically after any route.

I have also updated the buildLink to accept querys as argument:
event.buildLink(‘admin.ehBanner.dspBanner’,True,False,’ ’ ,‘bannerid =
#bannerId#’)

I hope you did this via the decorator and not the core source.

I updated the build link method from the files from the svn, it was
simple as to cut and paste. Great svn by the way, where you can see
the changes.

Goran,

I still don’t know what you did. Can you re-explain this.

I use SES URLs and name/value pairs in my apps. There isn’t a place to toggle this on/off. It has to be in your routes.cfm. Remember, the pretty URL handling will match the FIRST course in your routes.cfm file. Perhaps it’s matching another custom course.

First you mentioned that you use this route…

cfset addCourse(":handler/:action?/:id?")>

Then you mentioned your URLs are structured as:
package/handler/action/87

It seems you need…
<cfset addCourse(":package/:handler/:
action/:bannerId?")>

BTW, you also mentioned the request scope. You need not access that scope directly. The variables will appear the Request Collection. If you submit all of your route/course definitions and how you want the URLs structured, I’m sure someone here can show you how to alter your routes.

As a side note,

ColdBox 3.0 on the BER (nighty build) already supports turning off convention name value pairs per route basis.

In my applicatons list view I had event.buildLink
('admin.ehBanner.dspBanner',True,False,' ' ,bannerId = '#bannerId#')
for each record. And in my routes.cfm I had only <cfset addCourse
(":handler/:action?/:id?")> and of course it does not work like
expected. Then I changed event.buildLink
('admin.ehBanner.dspBanner',True,False,' ' ,'#bannerId#') and it
worked but I had to change my handler to accept id instead of
bannerId.

Then I removed <cfset addCourse(":handler/:action?/:id?")> and only
had
<cfset addCourse(":handler/:action")>
<cfset addCourse(":handler")>
in my routes file. But in my list view I did not changed back
event.buildLink('admin.ehBanner.dspBanner',True,False,'
' ,'#bannerId#') to event.buildLink
('admin.ehBanner.dspBanner',True,False,' ' ,bannerId = '#bannerId#').
Quite a mess before I got my things (and brain) togheter, and of
course much easier than expected!

In CB 2.6.3 there was no support for query strings in BuildLink wich I
needed, and I don´t wanted to do a full update of my CB, so I did a
cut and paste from the CVS version of requestContext.cfc (very easy
with the color support!). Later if I would like to update my CB
version I can do that whitout anny fear that I will lost the query
string suppport.

/göran

Still a great framework!

Hi Goran,

I suggest you read this: http://ortus.svnrepository.com/coldbox/trac.cgi/wiki/cbRequestContextDecoratorGuide

This way you don’t hack the core. THere are ways to extend it.