Friday, November 13, 2009

How to call a controller in FW/1

Sean Corfiled wrote a simple MVC framework a few months ago called FW/1 (check it out here). I have been following the discussion list since the beginning. Last night I finally gave it a try. I was very impressed by it's simplicity. There isn't alot of documentation but there doesn't need to be a whole lot because it is so easy and Convention based. I had a view up and running based on the getting started doc in just a few minutes. Very nice. It is not only easy, understanding the conventions will surely help my development in model-glue and other frameworks, even when I don't use a framework this will help with my mental and code organization.

Then I moved to controllers. I just couldn't grasp how they were called. I reread the docs a few times and finally went to bed a defeated man. This morning I reread once more and it clicked, and the docs explain it perfectly, I was just a little thrown by the verbage, which I shouldn't have been. In model glue I call an event like so:

<event-handler name="maint.city">
<broadcasts>
<message name="needCity"/>
</broadcasts>
<results />
<views>
<include name="body" template="maint/city.cfm" />
</views>
</event-handler>

In FW/1 your url would be http://www.whatever.com/myapp/index.cfm?action=maint.city

FW/1 automatically calls the city() function in the controllers/maint.cfc controller. It seems almost silly that I couldn't figure this out, but It did escape me for a minute. I knew to create a controller and where to put it, but I wasn't sure how to call different functions etc.. In model-glue I would broadcast different messages. So I was thinking maybe I needed to call functions from my view or something, like city = rc.controller.getCityById().

Turns out, as mentioned that FW/1 calls the city() function automatically and i can call other stuff from inside that function.

No comments: