Coldfusion-Best way to hide urls on pages by using CFSWITCH? -
Coldfusion-Best way to hide urls on pages by using CFSWITCH? -
i want build framework hides url's , learning cfswitch. navigation links queried in datatable. have tried query around cfswitch , maintain getting error
example: ?category=5&page=21 ( category=page_category , 5= page_categoryid , page page_id 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>
first, welcome coldfusion, it's great language, think you'll it. :)
what you're attempting here bad thought number of reasons, read on why , alternatives.
1) needlessly obfuscates you, developer. trust me larn hate 6 months when go in arbitrary changes , can't remember "14" means.
2) bad search engines - google ses urls more info (search engine safe).
3) numeric incrementing keys less secure descriptive texts. can loop on numbers , see pages, skipping navigation , seeing everything.
4) no perceivable advantages can't gained in other ways (which i'll show 1 next).
instead of going way have listed, arbitrary numbers link different elements- why not instead key them off of actual strings have meanings? if trying accomplish hiding actual page names processing request, why not instead utilize this:
http://www.domain.com/?/category/blog/page/links
instead of:
http://www.domain.com/page.cfm?category_id=21&page=5
in example, i'm not pointing actual directory, i'm going take cgi.querystring param (which contain string "/category/blog/page/links
") , parse , match key values. (see coldfusion list functions: http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=functions-pt0_13.html, utilize "/
" delimiter). can pull whatever logic need category "blog" , page "links" - can stored in database same "21" , "14". :)
now, on code...
as switch statement, works sort of set of if statements :
<cfswitch expression="value_to_check"> <cfcase value="possible_value_1"> <!--- ---> </cfcase> <cfcase value="possible_value_2,another_possible_value"> <!--- different ---> </cfcase> <cfdefaultcase> <!--- if none of above, ---> </cfdefaultcase> </cfswitch>
you have weirdness in include statement. can't specify url parameters in <cfinclude>
statement. think of literally grabbing code page specify , pasting document. that, no more, no less. therefore, can't specify url parameters. invalid :
<cfinclude template="../templates/page_bycategory.cfm?page_categoryid=#page_categoryid#">
additionally, it's pretty abnormal case statement have dynamic value such this:
<cfcase value="#page_categoryid#">
let me know if have questions / need clarification
coldfusion coldfusion-8
Comments
Post a Comment