In Coldbox, If I wanted to organize some of my han...
# box-products
p
In Coldbox, If I wanted to organize some of my handlers in a subdirectory in the handlers folder, what do I need to do to call them? IE: If I've got handlers > subfolder > my_handler.cfc and I call /subfolder/my_handler from the URL, I'm expecting it to run the /handlers/subfolder/my_handler.cfc and execute the
index()
method. Instead I'm getting "The event: [subfolder.my_handler] is not a valid registered event." I'm missing something simple here. Does anyone have any "do this, you idiot" advice?
b
@pegarm Does adding
/index
work?
If so, I'm thinking you will need to add a route for this to work
p
It does not.
b
Otherwise, you're hitting the default route which is
Copy code
:handler/:action?
which is matching
/subfolder/my_handler
Hmm, so what error do you get when you add index?
p
Adding
/index
results in "The event: [subfolder.my_handler.index] is not a valid registered event."
b
Copy code
<http://site.com/subfolder/my_handler/index|site.com/subfolder/my_handler/index>
Hmm, have you reinitted?
Also, does the old-school non-SES format work?
f
hmm… why not create a module instead of a sub folder? that might make more logical sense and ColdBox would be happier with that approach I would think
b
Copy code
<http://site.com/index.cfm?event=subfolder.my_handler.index|site.com/index.cfm?event=subfolder.my_handler.index>
Yes, a module is good, but the core ColdBox conventions should still work here 🙂
p
@bdw429s Same error using non-SES. @foundeo Thought of that as well, but just wanted some simple organization and was surprised when it barfed.
...so thought I'd ask.
f
cool, didn’t know you could create a subfolder in the handlers folder - carry on 🙂
p
Apparently you can't. LOL
b
It's called a "package" Pete. It works in handlers views, and models alike.
Same error using non-SES.
I would back up and make sure you have the CFCs you think you do in the folders you think you have them and ColdBox is reinitted
p
Confirmed. This is the directory structure locally and on the server. fwreinit has been passed. (Actually, CF froze earlier and I ended up restarting the whole machine.)
b
Ok, I just tested this and it works fine
I ran the following commands
Copy code
goto sandbox
mkdir packagetest --cd
coldbox create app
coldbox create handler subfolder/my-handler index
start --noopenbrowser
server open "/index.cfm?event=subfolder.my-handler.index"
server open "/subfolder/my-handler/index"
server open "/subfolder/my-handler"
All three of those server opens opened up my handler inside the package
p
I must be doing something stupid.
OH MY #prc.deity#.
Spell synchronize properly in the filename stupid.
🤦‍♂️
f
if it makes you feel any better I spelled false falase today 🙂
p
Sorry for the disruption. I owe the bar a round.
b
lol, glad to hear
What was the typo doing?
oh, I see. It was the actual CFC name
👍
p
I was trying to access synchronize_products which technically didn't exist.
f
oh I was guessing compiler error so coldbox didn’t know the cfc was there
b
I used to work on an app that LOVED to use the word
hierarchy
and I got really tired of typing that stupid word, lol
p
Going to go code in shame now.
b
Nah, we're just being rubber duck rubber duck, which is what we're here for 😁
p
The number of code commits titled "fixing stupidity" attached to my username is too damn high.