Skip to content

Instantly share code, notes, and snippets.

@lorenzo
Created January 21, 2015 14:38
Show Gist options
  • Save lorenzo/5227bf5dc4a1137bc19d to your computer and use it in GitHub Desktop.
Save lorenzo/5227bf5dc4a1137bc19d to your computer and use it in GitHub Desktop.
public function assetUrl($path, $options = array()) {
if (is_array($path)) {
return $this->url($path, !empty($options['fullBase']));
}
if (strpos($path, '://') !== false) {
return $path;
}
if (!array_key_exists('plugin', $options) || $options['plugin'] !== false) {
list($plugin, $path) = $this->_View->pluginSplit($path, false);
}
if (!empty($options['pathPrefix']) && $path[0] !== '/') {
$path = $options['pathPrefix'] . $path;
}
if (!empty($options['ext']) && strpos($path, '?') === false && substr($path, -strlen($options['ext'])) !== $options['ext']) {
$path .= $options['ext'];
}
if (isset($plugin)) {
$path = Inflector::underscore($plugin) . '/' . $path;
}
$path = $this->_encodeUrl($this->assetTimestamp($this->webroot($path)));
$path = rtrim(Configure::read('App.assetsUrl'), '/') . '/' . ltrim($path, '/');
$path = http_build_url($path, ['query' => 'v=' . Configure::read('App.current_version')], HTTP_URL_JOIN_QUERY);
return $path;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment