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

Where is the best place to put cfqueries?

Guest
May 16, 2012 May 16, 2012

Copy link to clipboard

Copied

Where is the best place to put cfqueries, in the <head> </head> or before the html tag? Thanks

Views

1.0K

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 , May 17, 2012 May 17, 2012

So before the doctype tag? Thanks

I just doesn't really matter.  the doctype, head, body, etc only matter to the browser; the CF tags only matter to CF.  The browser doesn't see the CFML, and CF doesn't care about the mark-up one bit: it just ignores it.

The best place - as I said - is not in the same file at all.  But if you insist on slapping your business logic in with your display logic, then the only consideration is that you need to set your variables before you use them.  Other than that: i

...

Votes

Translate

Translate
Community Beginner ,
May 16, 2012 May 16, 2012

Copy link to clipboard

Copied

Its best to put it before the html tag.

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 ,
May 17, 2012 May 17, 2012

Copy link to clipboard

Copied

The "best" thing to do is to not mix your display logic with your business logic in the same file: fetching stuff from the DBs hould not be coupled to outputing something based on that fetched data.

Read this lot:

http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller

http://docs.model-glue.com/

https://github.com/seancorfield/fw1/wiki

http://stackoverflow.com/questions/3361951/picking-a-coldfusion-mvc-framework

--

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
LEGEND ,
May 17, 2012 May 17, 2012

Copy link to clipboard

Copied

The best thing to do depends on the situation at hand.  There are times when Adam's suggestion makes sense.  There are others where it is overengineering.

If you are going to have your query, processing, and display code all in one file, it is important that you run your query before you attempt to process the results and that you do any processing before you attempt to display it.  However, I don't think it really matters where your coldfusion code is with respect to any html tags.

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
Guest
May 17, 2012 May 17, 2012

Copy link to clipboard

Copied

So before the doctype tag? Thanks

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 ,
May 17, 2012 May 17, 2012

Copy link to clipboard

Copied

So before the doctype tag? Thanks

I just doesn't really matter.  the doctype, head, body, etc only matter to the browser; the CF tags only matter to CF.  The browser doesn't see the CFML, and CF doesn't care about the mark-up one bit: it just ignores it.

The best place - as I said - is not in the same file at all.  But if you insist on slapping your business logic in with your display logic, then the only consideration is that you need to set your variables before you use them.  Other than that: it simply doesn't matter.

One consideration you might make is - even if it's all thrown into the same one file - at least separate the file itself into sections: have all your CFML code that gets your data at the top, and try to limit the CFML you have mixed in with the mark-up, eg: limit it to stuff like loops and conditionals.

But, seriously, separate your concerns.  Dan's pretty much just wrong when he said it's over-engineering. It's just sloppy to not to write tidy, well-maintained, well-organised code.

--

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
Community Expert ,
May 17, 2012 May 17, 2012

Copy link to clipboard

Copied

LATEST

goodychurro1 wrote:

Where is the best place to put cfqueries, in the <head> </head> or before the html tag? Thanks

In a separate CFM page or CFC then use, respectively, a cfinclude or cfobject tag to access the queries.

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