CacheBuster::createUrl PHP Method

createUrl() public method

Create a cache busted URL.
public createUrl ( string $url = '', string $time = null ) : string
$url string The URL to cache bust.
$time string The time string to append to the url.
return string The cache busted URL.
    public function createUrl($url = '', $time = null)
    {
        $time = $time ?: $this->time;
        if ($time) {
            $joiner = $this->getJoiner($url);
            $url .= $joiner . $time;
        }
        return $url;
    }

Usage Example

Example #1
0
 /**
  * Creates an absolute URL to a published asset. Eg: '/path/to/hash/asset.gif?cachebusted'
  * @param  string $path          The path to the asset. Eg: 'img/cat.gif'
  * @param  string $basePathAlias The alias path to the base location of the asset.
  * Eg: 'application.modules.mymodule.assets'
  * @return string                The absolute path to the published asset.
  */
 public function createUrl($path = null, $basePathAlias = null, $bustCache = true)
 {
     $basePath = '';
     if ($basePathAlias !== false) {
         $basePath = $this->getPublishedPathOfAlias($basePathAlias) . '/';
         $url = $basePath . $path;
     } else {
         $url = Yii::app()->createUrl($path);
     }
     if ($bustCache) {
         $url = $this->cacheBuster->createUrl($url);
     }
     return $url;
 }