getCurrentPackage() and RequestContentDecorator

Hey All,

I was looking at the RequestContext and wanting a simple way to get the Package name. Currently there is a getCurrentAction() getCurrentEvent() getCurrentHandler() etc…
Im trying to build the path to the setView() dynamically.

the folder structure i have is like so


in that handler.cfc i have the index() method

in the index method/action I have a call to event.setView(‘foo’);

I need ‘foo’ to be dynamic and to consider the Package in the event.

What i ended up doing is something like this…

public void function index(event,rc,prc){
var e = event.getCurrentEvent();
var package = ListFirst(e,’.’);
var handler = event.getCurrentHandler();
var action = ‘foo’;
//set default view to ‘foo’
event.setView(package & ‘/’ & handler & ‘/’ & action);

I know this would need some tweaking, but it gets me started.

I was reading about the RequestContentDecorator, and I wanted to add a getCurrentPackage() method to the request context. is this possible? I created my decorator cfc and added in the function but not sure how to make it available (if possible) to the request context.

How can I make this easier? Is there a way to specify in the view to automatically know where it is so I don’t have to put the full ‘path/to/view’?



Alright just an update. I was able to get the RequestContextDecorator to work, and I have a getCurrentPackage() method available to me now.
I thought I had reloaded the framework but I hadn’t so when i did, it showed up then.


Just out of curiosity what are you trying to achieve?

well I have an event like ?event='x.y.z' and in my handler I wanted
to call setView() but not have to hardcode setView('x/y/z');
It still doesn't seem to work when i do an ?event=x.y.z but it does
work when i do /x/y/z.

i was trying to do a setView(event.getCurrentPackage() & '/' &
event.getCurrentHandler() & '/' & event.getCurrentAction());

okay event=x.y.z works fine. I had a silly typo in the action, but hopefully it will make sense to what I’m doing. If you know of a better way, I am open.

Ok seems very strange to go against the conventions of ColdBox here, so I was curious what you are trying to achieve…

Am i going against the conventions?

In the end ill have urls like so

if you didn't specify 'z' i wanted to set the view to z. The default
is index I know, but for a couple of the urls, I need to set the view
to z as the default.

also for example would just need to be seen as foo.reports.index

Maybe Im making this complicated, but I'm not sure how to do what I
want to do the "right" way.

That is exactly how ColdBox works, except for the action. But why would you want every action to be the same?

I'm not sure I understand.
the package is different.
I needed 3 separate packages, but they each act similar, and have the
same handler names and actions.
Guess it is hard to explain.