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
handlers
programA
handler.cfc
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.
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.
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.
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.