Skip to content

Instantly share code, notes, and snippets.

@nathanbrauer
Created November 13, 2013 19:44
Show Gist options
  • Save nathanbrauer/7455139 to your computer and use it in GitHub Desktop.
Save nathanbrauer/7455139 to your computer and use it in GitHub Desktop.
<?php
// Add to framework/model/Image.php
// Ensures all Image URLs have a cachebuster appended so when an image is replaced (same file name), the correct image appears in the browser.
public function getURL() {
$LastEdited = $this->LastEdited;
if (!$LastEdited) {
$Original = File::find($this->getFilename());
if (!$Original || !$Original->LastEdited) return parent::getURL();
$LastEdited = $Original->LastEdited;
}
return parent::getURL().'?'.preg_replace('/[^0-9]+/i','',$LastEdited);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment