I know how to do this in ColdFusion, I am trying to get the same syntax to define root directories, sub directories and filenames as needed (the goal is that when the client clicks on any page it’s title will be defined by the section or directory it lies in).
This is the code I have for CF (sorry there is alot of it):
<cfset REQUEST.directory_path = listDeleteAt(CGI.script_name, listLen(CGI.script_name, "/"), "/")>
<cfset REQUEST.directory_top = listFirst(CGI.script_name, "/")>
<cfset REQUEST.filename = listFirst(listLast(CGI.script_name, "/"), ".")>
<!--- Array of directory names --->
<cfset REQUEST.directory_array = ListToArray(REQUEST.directory_path,"/")>
<cfif ArrayLen(REQUEST.directory_array) GTE 1>
<cfset REQUEST.directory_parent = REQUEST.directory_array[ArrayLen(REQUEST.directory_array)]>
<cfelse>
<cfset REQUEST.directory_parent = REQUEST.filename>
</cfif>
<cfset VARIABLES.filename = REQUEST.filename>
<cfset VARIABLES.directory = REQUEST.directory_parent>
<cfset VARIABLES.primarydir = REQUEST.directory_top>
<cfset VARIABLES.secondarydir = GetToken(REQUEST.directory_path, 2 , "/")>
<cfset VARIABLES.tertiarydir = GetToken(REQUEST.directory_path, 3 , "/")>
<cfset VARIABLES.quaternarydir = GetToken(REQUEST.directory_path, 4 , "/")>
<cfif VARIABLES.primarydir EQ "index.cfm">
<cfset VARIABLES.primarydir = "index">
</cfif>
Then I have a simple switch statement to define my various sections:
<cfswitch expression="#VARIABLES.PrimaryDir#">
<cfcase value="photography">
<cfset VARIABLES.page_title_section = "Home">
<cfset VARIABLES.PrimaryDir EQ 'photography'>
</cfcase>
<cfcase value="clients">
<cfset VARIABLES.page_title_section = " Clients">
<cfset VARIABLES.PrimaryDir EQ 'clients'>
</cfcase>
etc, etc.
I think I am OK creating the switch statement in PHP, but how do I define the directory structure as above? I did look here: http://php.net/manual/en/function.pathinfo.php but I am not 100% sure what I am passing to php for this to work.
Hope someone can help.
I’m know next to nothing about ColdFusion, but if I understand you correctly you can get the same effect by inspecting the
$_SERVER['REQUEST_URI']property:This will give you a single dimensional array equal to the current request. For instance if a user requests the following URL:
Then
$requestArraywill be:If the user requests the home page (http://www.domain.com) then the request array will be empty.
For more information, check out the manual entry for
$_SERVER