I run fw/1 in a subdir of a legacy site, gradually...
# fw1
a
I run fw/1 in a subdir of a legacy site, gradually migrating content to it over time. Sometimes, from outside of the fw/1 subdir, I want to be able to access content/data that a fw/1 controller is already written for. The way i have been accessing this is via a cfhttp call - but that seems kinda lame and inefficient on the same site. If i try to create the controller as a component and access it that way, it fails as the controller init() methods are written to require a reference to the fw cfc like below. Any reason i cannot create a reference to the main framework.one component in a root level application variable and just pass that in to the init methods?
Copy code
public function init(fw) {
        variables.fw = fw;
    }
t
Not sure I understand your question fully. But you say your FW1 is in a subdir and you want a cfc on the root level to work like a FW1 action/controller? In general, that would not be possible because you have your legacy site's Application.cfc on the root level and it is the Application.cfc that executed for your root-level cfc. For fw1 logic to work you need to have fw1's Application.cfc to in action, that is, you will need to instruct ColdFusion/Lucee to load FW1's Application.cfc other than your root level Application.cfc - for which, I think is not possible
Well, technically speaking it may be possible, but that will require you to merge your root-level Application.cfc logic to FW1's Application.cfc logic, and is usually quite a difficult task
a
My thought was why is that code in the controller - shouldn't it be in a service? You'd be able to call the service from your legacy app.
a
thanks! Tomy - makes sense - I just wanted the cleanest way to reuse the code/data in the fw1 subdir - which does inherit from the top level app.cfc btw. I might just have to roll with CFHTTP until I can bit the bullet and get the whole site under fw1, especially if i want to leverage views. Yorik - yeah that is my best option, I think, if I don't need any logic from views/controllers. I did just try it and it didn't work as the service I am trying to use depends on a commonService that I guess the fw1 plumbing injects for me. So unless there is an easy way around that, I might be out of luck.
a
If it's the same application then you should be able to grab your service from DI1. Not got a FW1 app to test on but think it'll be in the application scope so something like
di1 = application["framework.one"].getBeanFactory()
. Then
di1.getBean('myservice')
a
That is really helpful. So they are part of the same application except that the fw1 app.cfc inherits from the base app.cfc. Got it working quickly with your idea, essentially passing a reference to the fw1 component up to the application scope, then setting the request._fw1 in the parent app when i needed it. Then I could get a di1 object and call my service. (application["framework.one"] on my install is just a struct) I will have to look at this more closely to see what the side-effects are of storing the fw1 component in the application scope. I'd also have to trigger a request to the child fw1 app when the parent starts, to get the fw1 component reference passed up to the parent.
a
Ah OK - sorry couldn't quite recall how it works. I think
application["framework.one"].factory
should give you di1 then (I'm reading the source code on github!)
🙌 1