Skip to content

Instantly share code, notes, and snippets.

@petrabarus
Created September 13, 2012 02:16
Show Gist options
  • Save petrabarus/3711425 to your computer and use it in GitHub Desktop.
Save petrabarus/3711425 to your computer and use it in GitHub Desktop.
<?php
/**
* @property-read CWidget $owner
* @method CWidget getOwner()
*/
class WidgetAssetBehavior extends CBehavior {
private static $_assetPaths;
/**
* @param boolean $checkTheme
* @return string
*/
public function getAssetPath($checkTheme) {
$className = get_class($this->owner);
if (isset(self::$_assetPaths[$className]))
return self::$_assetPaths[$className];
else {
$viewPath = $this->owner->getViewPath($checkTheme);
return self::$_assetPaths[$className] = substr_replace($viewPath, 'assets', strrpos($viewPath, 'views'), strlen('views'));
}
}
/**
* @param string $path
* @param boolean $hashByName
* @param integer $level
* @param boolean $forceCopy
* @return string an absolute URL to the published asset
* @throws CException if the asset to be published does not exist.
*/
public function publish($path, $hashByName, $level, $forceCopy) {
/* @var $assetManager CAssetManager */
$assetManager = Yii::app()->assetManager;
return $assetManager->publish($path, $hashByName, $level, $forceCopy);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment