Coldfusion-使用 CFSWITCH 隐藏页面 URL 的最佳方法?

发布于 2024-11-19 02:44:58 字数 758 浏览 1 评论 0原文

我想构建一个隐藏 URL 的框架,并且我刚刚学习 CFSWITCH。导航链接在数据表中查询。我尝试查询 cfswitch 并不断收到错误

示例: ?category=5&page=21 (其中类别=page_category 且 5= page_categoryid 数据表中的页面 page_id 为 21 )

<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 template="/modules/blog/">
      </cfcase>
   </cfswitch>
</cfoutput>

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 template="/modules/blog/">
      </cfcase>
   </cfswitch>
</cfoutput>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

-柠檬树下少年和吉他 2024-11-26 02:44:58

首先,欢迎使用 ColdFusion,它是一门很棒的语言,我想您会喜欢它。 :)

由于多种原因,您在这里尝试的想法非常糟糕,请继续阅读原因和一些替代方案。

1)它不必要地向你(开发者)混淆了它。相信我,从现在起 6 个月后,当你回去进行一些随意的更改并且不记得“14”意味着什么时,你会学会讨厌它。

2) 这对搜索引擎不利 - 谷歌 SES 网址以获取更多信息(搜索引擎安全)。

3) 数字递增键不如描述性文本安全。我可以循环浏览数字并查看所有页面,跳过导航并查看所有内容。

4)你不会获得任何通过其他方式无法获得的明显优势(接下来我将向你展示)。

与其按照您列出的方式进行处理,链接到不同元素的任意数字 - 为什么不将它们与具有含义的实际字符串分开?如果您想要完成的是隐藏正在处理请求的实际页面名称,为什么不使用类似这样的内容:而

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

不是:

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

在我的示例中,我没有指向实际目录,我将采取cgi.querystring 参数(将包含字符串“/category/blog/page/links”)并解析它并将其与键值匹配。 (请参阅 Coldfusion 列表函数:http://livedocs.adobe.com/ Coldfusion/8/htmldocs/help.html?content=functions-pt0_13.html,使用“/”作为分隔符)。然后我可以提取类别“博客”和页面“链接”所需的任何逻辑 - 可以将其存储在数据库中,就像“21”和“14”一样。 :)

现在,转到您的代码...

至于 switch 语句,它的工作原理有点像一组 if 语句:

<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>

您的 include 语句中也有一些奇怪的地方。您不能在 语句中指定任何 url 参数。可以将其视为从您指定的页面中抓取代码并将其粘贴到文档中。它正是这样做的,不多也不少。因此,您不能指定 url 参数。这是无效的:

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

此外,case 语句具有如下动态值是非常不正常的:

<cfcase value="#page_categoryid#">

如果您有任何问题/需要澄清,请告诉我

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文