Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
LiveWhale custom module to save the current URL segments as XPHP variables
<?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