Last active
April 19, 2017 14:30
-
-
Save karlhinze/965da6f6f6441dde4cc19efee2d53893 to your computer and use it in GitHub Desktop.
LiveWhale custom module to save the current URL segments as XPHP variables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Provide access to each segment of the server path with the variable: <xphp var="url_segment_[x]" /> | |
$_LW->REGISTERED_APPS['server_path']=array( | |
'title'=>'Server Path', | |
'handlers'=>array('onLoad') | |
); | |
class LiveWhaleApplicationServerPath { | |
public function onLoad() { // on module load | |
global $_LW; | |
// Get the server path from the url and split it into segments, removing the first slash | |
$url_segments = explode('/', trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/')); | |
$num_segments = count($url_segments); | |
// Return global variables for each segement of the server path | |
for($i = 0; $i <= $num_segments; $i++) { | |
$j = $i+1; | |
$GLOBALS['url_segment_'.$j] = @$url_segments[$i]; | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment