开发者

Coldfusion-Best way to hide urls on pages by using CFSWITCH?

I want to build a framework that hides the URL's and am just learning CFSWITCH. Navigation links are queried in datatable. I have tried to query around cfswitch and keep getting error

Example: ?category=5&page=21 ( where category=page_category and 5= page_categoryid and page is page_id is 21 in datatable )

<cfoutput query="pagecategories" group="page_categoryid">
   <cfswitch expression="#URL.category#">
      <cfcase value="21">
         <cfinclude template="../templates/index_welcome.cfm">
      </cfcase>

      <cfcase value="#page_categoryid#">
         <cfinclude template="../templates/page_bycategory.cfm?page_categoryid=#page_categoryid#">
      </cfcase>

      <cfcase value="22">
         <cfinclude 开发者_如何学Ctemplate="/modules/blog/">
      </cfcase>
   </cfswitch>
</cfoutput>


First, welcome to ColdFusion, it's a great language, I think you'll like it. :)

What you're attempting here is a really bad idea for a number of reasons, read on for why and some alternatives.

1) it needlessly obfuscates it from you, the developer. Trust me you will learn to hate it 6 months from now when you go back in for some arbitrary changes and can't remember what "14" means.

2) it is bad for search engines - google SES urls for more info (search engine safe).

3) numeric incrementing keys are less secure than descriptive texts. I can just loop over numbers and see all your pages, skipping your navigation and seeing everything.

4) you get no perceivable advantages that can't be gained in other ways (which I'll show you one next).

Instead of going about it the way you have listed, arbitrary numbers that link to different elements- why not instead key them off of actual strings that have meanings? If what you are trying to accomplish is hiding the actual page names that are processing the request, why not instead use something like this:

http://www.domain.com/?/category/blog/page/links

instead of:

http://www.domain.com/page.cfm?category_id=21&page=5

In my example, i'm not pointing to an actual directory, I'm going to take the cgi.querystring param (which will contain the string "/category/blog/page/links") and parse it and match it to key values. (see coldfusion list functions: http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=functions-pt0_13.html, use "/" as delimiter). Then I can pull up whatever logic i need for category "blog" and page "links" - which can be stored in a database just the same as "21" and "14". :)

Now, on to your code...

As for the switch statement, it simply works sort of like a set of if statements :

<cfswitch expression="value_to_check">
<cfcase value="possible_value_1">
    <!--- do something --->
</cfcase>
<cfcase value="possible_value_2,another_possible_value">
    <!--- do something different --->
</cfcase>
<cfdefaultcase>
    <!--- if none of the above, do this --->
</cfdefaultcase>
</cfswitch>

You also have some weirdness in your include statement. You can't specify any url parameters in a <cfinclude> statement. Think of it as literally grabbing the code from the page you specify and pasting it into the document. It does exactly that, no more, no less. Therefore, you can't specify url parameters. This is invalid :

<cfinclude template="../templates/page_bycategory.cfm?page_categoryid=#page_categoryid#">

Additionally, it's pretty abnormal for the case statement to have a dynamic value such as this:

<cfcase value="#page_categoryid#">

Let me know if you have any questions / need clarification

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜