Assetmanager - How To Determine Webroot In Config

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

May be ths can help you.http://www.yiiframework.com/forum/index.php/topic/12258-improved-assetmanager

Thanx, for tip, my issue is only related to incorrectly calculated web root.

I solved problem by overriding CAssetManager methods - here is my class:


<?php

/**

* Configuration - main.php:

	'assetManager'=>array(

		'class'=>'AssetManager',

		'basePath'=>dirname(__FILE__).'/../../web/media/_assets/',

		'baseUrl'=>'media/_assets/',

	),

*/

class AssetManager extends CAssetManager{


	/**

	 * @var string base URL for accessing the publishing directory.

	 */

	private $_baseUrl;


	/**

	* Override parent method to allow dynamic URL web root

	*/

	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;

	}


	/**

	* Must be here because parent uses private property:-(

	* @param string $value

	*/

	public function setBaseUrl($value)

	{

		$this->_baseUrl=rtrim($value,'/');

	}


}

It is probably least possible overhead and it will allow publishing all assets anywhere out of direct webroot.

This way, assets can be placed into static CDN mapped subdomain.

Thanx

.:: XL ::.