I have an app that loads a module from an external location:
`
/app
- /handlers
– /admin
— test.cfc - /models
- /views
`
elsewhere on the file system…
`
/common
- /modules
– /example
— /handlers
---- /admin
----- test.cfc
— /models
— /views
`
The common example module will be loaded in multiple applications, so for convenience I made the directory structure similar so that common code is in one place and the module can tell the host application to do what’s specific to it by calling
runEvent(<some host application handler>)
/app has in its Coldbox.cfc config:
modulesExternalLocation = ["/common/modules"]
and I can run events by hitting them via URL (SES configured) as expected and they work great, except in one case.
I have a handler, /example/admin/test/ajax, that I’m hitting via ajax. In that handler I have the following:
runEvent(event = "admin.test.ajax", private = true);
which hits /app/handlers/admin/test.cfc’s private ajax() function. That function puts things in the prc. If, in that function I do
prc.module.view = "<h1>Hello, all the things</h1>"
it returns just fine. But if I do
prc.module.view = renderLayout(layout = "layout.div", view = "admin/test/ajax")
execution never returns to the /example handler that made the runEvent call. In fact, execution doesn’t even complete in the /app handler that is being executed by runEvent (I put a throw right after the renderLayout call and it never throws). Instead, execution jumps straight to a breakpoint I have set in /example/views/admin/test/ajax.cfm where it’s expecting prc.module.view to exist, and throws a reference error because it’s undefined.
I’ve used renderLayout extensively in ajax calls before and never had any issues. Things like:
local.return = { status = "success", view = renderLayout(layout = "layout.div", view = "some/view/here") }; event.renderData(type = "JSON", data = local.return); ... jQuery.ajax(...) .done(function(response) { jQuery('#populateViaAjax').html(response.VIEW); });
This has never short-circuited the execution of the CB event handler before. I’m wondering if it’s something to do with how modules and runEvent interact.
Am I abusing the framework? I’d like the host application handler to be the one that knows whether to put a static string or the result of a renderLayout call in prc.module.view, as that’s logic specific to the host application. All the common example module’s view cares is that there’s something there to output. I can’t really use viewlets since those are self-contained, and the handler logic is split between the module and the host application (that is, the common module calls its services to get data to put in the prc, and the host application is expected to put other things in the prc).
I’ve also tried having the /app ajax handler simply return a struct and have the common module handler be the one to blindly put it in the prc, but it’s the renderLayout call that it’s not making it past, so that part is moot.
Any thoughts?