I was planning on abandoning the framework and going back to my old
ways but then realized that I could just do a cfinvoke or create an
object and call the service as I needed and still call the services
with the <cfset variables.fw.service("x.y", "z") > as I needed to. I
was too short-sighted to see this at first but please let me know your
thoughts of this approach. Am I missing something? Do you see any
issues with this approach? Or does this totally fail the MVC
approach?
Hopefully your feedback will help other newbies who go through my same
issues.
i.e. My original code in the controller wanted to do something like
<cffunction name="control" output="false">
....
<cfset rc.isMobile = 0>
<cfset variables.fw.service("test.isMobilePhone", "isMobile")>
<cfif rc.isMobile EQ 1>
<cfset variables.fw.service("test.showOffer", "showOffer")>
<cfelse>
<cfset variables.fw.service("test.showWarning", "showWarning")>
</cfif>
</cffunction>
which wouldn’t work since the service calls are executed in a series
but control has passed from the controller.
So, I am calling it this way now:
<cffunction name="control" output="false">
....
<cfset rc.isMobile = 0>
<cfinvoke component="services.test" method="isMobilePhone"
phone="#phonenum#" returnVariable="local.isMobile">
<cfif local.isMobile EQ 1>
<cfset variables.fw.service("test.showOffer", "showOffer")>
<cfelse>
<cfset variables.fw.service("test.showWarning", "showWarning")>
</cfif>
</cffunction>
I am just curious if you could have controlled the timing of your
service method with
<cffunction name="start[itemName]>
<cfarguments name="rc" required="true" type="struct">
</cffunction>
From the docs @ http://fw1.riaforge.org/wiki/index.cfm/DevelopingApplicationsManual#Designing_Controllers
Here is the full list of methods called automatically when FW/1 is
asked for section.item:
controllers/section.cfc:before()
controllers/section.cfc:startitem()
controllers/section.cfc:item()
services/section.cfc:item()
(any additional service calls that were added via the service() API
call)
controllers/section.cfc:enditem()
controllers/section.cfc:after()
Methods that do not exist are not called.
As an FW/1 newbie and applying this on a new project, I was getting
frustrated with having to call the service methods with <cfset
variables.fw.service("x.y", "z") > and having to work around the
workflow since the services are called in order (i.e. after the
startController and controller methods are called).
On Feb 3, 12:10 pm, spills <spillsmi...@yahoo.com> wrote:
> OOPS -- hit post with the tab key -- most anoying!
>
> From the docs @http://fw1.riaforge.org/wiki/index.cfm/DevelopingApplicationsManual#D...
<cffunction name="startcontrol">
<cfarguments name="rc" required="true" type="struct">
<cfset variables.fw.service("test.showOffer", "showOffer")>
</cffunction>
Here is what I was(really) thinking:
In Controller:
<cffunction name="startcontrol">
<cfarguments name="rc" required="true" type="struct">
<cfset variables.fw.service("test.isMobilephone", "rc.phonenum")>
</cffunction>
In Services:
some function returns true/false of isMobile you can return a struct
if needed
In Controller:
<cffunction name="control" output="false">
....
<cfif rc.data.isMobile>
Ryan
Perhaps some philosophy here will help:
FW/1 has a set of conventions that are intended to remove the need for
explicit calls _in many cases_ but you should not try to shoehorn your
code into that pattern if your needs are greater than the conventions.
The general patterns of usage that are expected are:
controller: section.item()
service: section.item()
or:
controller: section.startitem()
service: section.item()
controller: section.enditem()
You can optional queue up additional (non-default) service calls if
that is convenient.
Those are just the conventions.
It's perfectly reasonable to have component-level service calls inside
your controller methods too and that's the non-convention way to do
things:
controller: section.item() -> rc.stuff =
variables.myService.someMethod( rc.something );
where section.cfc sets up variables.myService in its constructor -
init() - or has it passed in via injection.
--
Sean A Corfield -- (904) 302-SEAN
Railo Technologies US -- http://getrailo.com/
An Architect's View -- http://corfield.org/
"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood
Option 1 - I was also wondering why I didn't just do the option 1 you
listed and then realized that I needed to set more "rc" variables
within the controller and that’s why I wanted the info back in the
controller (since the service only returns 1 value back unless I used
a struct - which thinking about now - may have worked).
Option 2 - This is what I had in mind and was doing although I left my
functions within a helper CFC in the "services" folder or within the
"services.test.cfc" named uniquely.
I am not yet familiar with Coldspring or other bean factories though I
have a good idea of what it does. I hope to sink my teeth into it
soon. The XML configuration bean is what is intimidating me more than
the coldfusion code.
@spills - we all have those days and when it rains, it pours :-)
@Ryan - The showOffer and showWarning are just random functions I came
up with and not what I actually used/needed to do and tried to obscure
it due to job privacy concerns. There may have been a better way to do
this but as the job functions kept changing throughout this project I
had to sort of keeping patching it up.
@Sean - Thanks again for reminding me to do as I see fit. Like I said,
I was a little short-sighted initially and remembered your philosophy
of doing things as the user saw fit and that’s why I finally went with
this approach and at the end appreciate this framework since it still
keeps the views free of any complicated code. I plan to use this for
another bigger and more complex project and fortunately know most of
the requirements for this project. But I am sure I will have more
questions for all of you soon.
I just hope this post will clarify the usage and benefits for other
newbies who are on the fence.
> Railo Technologies US --http://getrailo.com/
> An Architect's View --http://corfield.org/