Yii Framework Forum: Is This Behaviour Expected? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Is This Behaviour Expected? assets and javascript path Rate Topic: -----

#1 User is offline   Jose Serodio 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 27-December 12

Posted 20 February 2013 - 07:50 PM


I'm publishing module's assets (js+images+css) with:
$url = Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('application.modules.imo.assets'),false,-1,YII_DEBUG);

Registering js script:

Everything is published correctly, the browser requests the script in folder base/assets/xxxxxxx/js/, but inside the script, when I try to set an image source path, with something like ../images/image.png I always get the base folder not the assets one... document.url returns the base folder too...

Here is the script:

var imgs = {
1: '../images/img1.png',
2: '../images/img2.png',
3: '../images/img3.png'

$.getJSON('list/get', updateIms);
function updateIms(data) {

	$.each(data, function (i, item) {

		var listitem = 
				"<div class='imlistitem'>" +
					"<div class='imlistitemtipo'>" +
						"<img src='" + imgs[item.tipo] + "'/>" +
					"</div>" +

I got an workaround but I don't like it, in the script I get the path with:
var scripts = document.getElementsByTagName("script");
var path = scripts[scripts.length-1].src;

And then I construct the image path string accordingly.


Share this topic:

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users