[ColdBox 4.2.0] Global query to use on all views

Hello,

I would like to include a global query for use on all views. I thought I could do this with an interceptor, which might be true and maybe I’m setting the result set incorrectly. What is the proper way to set a global query for inclusion on views.

Thanks,
Marc

I would recommend setting the query into the prc scope (private request collection). The easiest way to do this is in a preProcess interceptor or in your requestStartHandler handler.

Thanks!

~Brad

ColdBox/CommandBox Developer Advocate
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Thanks for the quick response, Brad.

I had originally tried the preProcess on the interceptor with setting it to prc. But the view does not see it. Do I need to call it differently on the view instead of using prc? And interesting enough, the postProcess does see the query created in the preProcess. So I’m not sure why the view doesn’t.

Attached is my interceptor. Maybe I’m missing something.

Thanks,
Marc

authentication.cfc (1.16 KB)

prc is not an argument to interceptors (yet anyway-- I think Luis put in a ticket for that recently) so what you’re acttually setting is variables.prc.get_participant!

You need to do
event.setPrivateValue( ‘get_participant’, etc.getParticipant(…) )
or just get out the prc like so:

var prc=event.getPrivateCollection.
prc.foo = bar;

The reason you’re used to this “working” in handlers is that we pass prc in as an argument to the methods so every time you access it, you’re actually accessing arguments.prc.

Thanks!

~Brad

ColdBox/CommandBox Developer Advocate
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Opps,

var prc=event.getPrivateCollection.

should have read

var prc=event.getPrivateCollection();

Thanks!

~Brad

ColdBox/CommandBox Developer Advocate
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Thanks Brad!!

That worked great! And thanks for the explanation, which will help me.

Marc