Hi,
does anybody know, whether it is possible to configure AssetManager in config.main with some kind of web root alias?
Currently following is possible - hard-coded paths - config/main.php:
'assetManager'=>array(
'basePath'=>dirname(__FILE__).'/../../web/media/_assets/',
'baseUrl'=>'web/media/_assets/',
),
I need to set path dynamically like so:
'assetManager'=>array(
'basePath'=>dirname(__FILE__).'/../../web/static/_assets/',
'baseUrl'=>'application.web.static.assets',
),
This is because development, testing and productions server may each have different webroot.
When I dont set any root, paths are determined correctly, because CAssetManager uses request URL:
public function getBaseUrl()
{
if($this->_baseUrl===null)
{
$request=Yii::app()->getRequest();
$this->setBaseUrl($request->getBaseUrl().'/'.self::DEFAULT_BASEPATH);
}
return $this->_baseUrl;
}
Unfortunatelly, this code is always skipped when setting URL in config.
I think it is not correct and URL root should always be taken from request since assets directory must be public. So the code above should be like so:
public function getBaseUrl()
{
static $done;
if(!$done)
{
$request=Yii::app()->getRequest();
$this->setBaseUrl($request->getBaseUrl().'/'.($this->_baseUrl ? $this->_baseUrl : self::DEFAULT_BASEPATH));
$done = true;
}
return $this->_baseUrl;
}
Unfortunatelly, overriding class in config does not work because of private properties (and that’s why private visibility should never be used in frameworks!):
'assetManager'=>array(
'class'=>'AssetManager',
)
So has anybody similar problem with some pretty solution?
Thanx in advance.
Lubos