extension assets

Hi all

in my extensions folder I have an extension I’m tweeking

it contains an assets folder and a views folder

I added images to the assets folder

but I can’t find the right syntax to simply get the images path to show my images in my view ?

I thought something like for the modules would work


or $this->ext->assetsUrl like $this->module->assetsUrl

but I can’t seem to figure it out ?

forgive my niewbeeness

Thanks for your help


The application’s assetManager is the component that is intended to be used to publish assets that come with extensions. So, any extension should use code like this:

// guess we're in your views folder

$filepathExtensionImages = dirname(__FILE__) . '../assets/images';

// assetManager will publish the folder and return the url to that folder

$baseUrl = Yii::app()->assetManager->publish( $filepathExtensionImages );

// use one of the images

$urlImage1 = "$baseUrl/image1.jpg";

echo '<img src="'.$urlImage1.'" />';

You can also publish your images one by one, instead of publishing the whole folder.

See CAssetManager::publish() for details.

Thanks for the hint Ben, it got me on a good track but…

Though I find this solution quite strange,

couldn’t we use our Extension’s class (extending CWidgets) attribute (assetUrl) or method getAssetUrl directly from the extension’s view ?

Maybe it’s due to the structure of the great extension I’m trying to tweek ,

which is yii-debug-toolbar

this works but doesn’t seem so great

in my view page:

<?php $baseUrl = Yii::app()->assetManager->publish( Yii::getPathOfAlias('ext.myExtension.assets') ); ?>

this returns the path (unique Id) of my extension’s assets from the application’s asset folder

<img src="<?php echo $baseUrl; ?>\feature.jpg" alt="" class="feature-image" height="1280" width="960" />

I’m not sure to which methods you refer. If I look at CWidget’s API, I can’t see anything related to assets.

Does the yii-debug-toolbar extension come with some helper methods related to asset publishing? If so, I guess the author of that extension could best explain how to use them.

Hi Tibor) You have my email and can ask directly ) I will be glad to share my knowledge)