• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Accessing cfc via form

New Here ,
Apr 21, 2010 Apr 21, 2010

Copy link to clipboard

Copied

I am dipping my toe into my first cfc...trying to get more oop oriented.

I have a cfc that I am developing for a login to will check if a user name exists in the db

...so that is one function.

I have a second function that accesses a web service from our Oracle environment that returns a boolean if they customer number is accurate and is on support.All of our customers know their number.

So I created a registration form with a user name field and a customer number field. In my action attribute, I reference my cfc as follows...

action="cfc/login.cfc?method=chkUser"

This seems to work fine for one function. I have two functions as I mentioned, so I thought I could "daisy-chain" the methods...

action="cfc/login.cfc?method=chkUser&method=Oraclechk"

This did not work. Seems that it looks for a method that is chkUser,Oraclechk, which of course, does not exist.

So here are my questions...

  1. Is there a way to submit multiple methods through the action?
  2. If not, then I think the best thing would be to combine my functions into one. The only problem is that one function (chkUser) returns a string, which tells the end user that the user name exists [my plan was to perform a cfif within my processing to display that to the end user]. The other function simply returns a status of active or inactive.

Thoughts?

Thanks,

Clay

TOPICS
Advanced techniques

Views

927

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Apr 22, 2010 Apr 22, 2010

My approach would be:

Use cfobject or createobject to get access to the methods in the cfc.

Call the two functions separately.  You can use cfset or the equivalent cfscript code for this.

Process the returned information according to your requirements.

Votes

Translate

Translate
LEGEND ,
Apr 21, 2010 Apr 21, 2010

Copy link to clipboard

Copied

A better way is to not submit forms to cfc pages.  Instead, submit them to cfm pages which call the cfc pages.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 21, 2010 Apr 21, 2010

Copy link to clipboard

Copied

ok...I was simply following an article written by Ben Forta. I am fine doing it another way...Do you have an example somewhere?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 22, 2010 Apr 22, 2010

Copy link to clipboard

Copied

My approach would be:

Use cfobject or createobject to get access to the methods in the cfc.

Call the two functions separately.  You can use cfset or the equivalent cfscript code for this.

Process the returned information according to your requirements.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 22, 2010 Apr 22, 2010

Copy link to clipboard

Copied

Thanks for pointing me in the right direction. I believe I have it figured out. I would appreciate any feedback on my code though

, since this is my first cfc. I will see if I can attach.

One thing I am still fuzzy on is the need for init().

Cannot seem to attach code...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Apr 22, 2010 Apr 22, 2010

Copy link to clipboard

Copied

the init() is not needed.

But the ColdFusion Component does not have the automatic constructor method that many other Object Orientated Systems do.  It is the psudo constructor area.  Which is code outside of any <cffunction...> block.  Code placed here, ususally at the top of the <cfcomponent...> block, will be ran for every invokation of the component.  But one can not provide any parameters to this function.

Thus, with a need for a constructor method, the ColdFusion community as set on a standard of the init() function.  That can be called when one invokes the component, to initilze the object with desired parameters.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 22, 2010 Apr 22, 2010

Copy link to clipboard

Copied

OK...I get it (me thinks)....So it is a good practice to create an init

function in every cfc even though it is not needed as I could place code inside the init that would fire every time the cfc is instantiated.

Thanks you have been very helpful. I am attempting to get more oop oriented and separate my cf code more logically (MVC and such)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Apr 22, 2010 Apr 22, 2010

Copy link to clipboard

Copied

Well, I wouldn't create one if I did not need it in a specific Component.

But if your component needs one, the CF community standard is to name it init() so the chances are better that your code would be understood by others if you used init() rather then start() or constructor() or some other random function name.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 22, 2010 Apr 22, 2010

Copy link to clipboard

Copied

LATEST

Note that when using CF9's Hibernate integration, init() methods are treated as "proper" constructors, in that they are called automatically when an entity is created.

So using init() is moving away from being a de facto standard approach to this, and moving more towards an actual "official" implementation.  If that makes sense.

If I have a CFC that will have stateful instances, I'll always implement an init() method, and always call it when I use the CFC.  Even if all the init() does is "return this".  I'm not sure there's really a good reason for doing this, though, I have to admit.

For CFCs that are simply a collection of like-minded functions, I don't bother.

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation