Image logo usage with default layout

Hi,

Have just generated a new yii webapp, and after the config changes, next thing I am trying to do is change a bit of the look-n-feel.

Want to have a company logo (currently, just a 120x80 color-burst .png file) placed on the page header area, and I’ve tried couple of things like directly embedded <img> html tag, like this…

<div class="container" id="page">

&lt;div id=&quot;header&quot;&gt;


	&lt;div id=&quot;logo&quot;&gt;&lt;img url=&quot;myappweb/images/colorbox.png&quot; alt=&quot;Color logo&quot; /&gt;&lt;/div&gt;

to, an invocation like this…

<div class="container" id="page">

&lt;div id=&quot;header&quot;&gt;


	&lt;div id=&quot;logo&quot;&gt;&lt;?php echo CHtml::image('myappweb/images/colorbox.png','Color logo'); ?&gt;&lt;/div&gt;

and also tried with relative path like:

‘../../images/colorbox.png’

Situation is that with the CHtml::image() approach, the header area is empty, but with direct <img> tag approach, I get the alt text displayed, but not the image.

The browser ‘view source’ tells me that the HTML generation is fine, and the <img> line shows up in the correct place. Also directly accessing the image file in browser at http://localhost:8080/myappweb/images/colorbox.png works well. So my suspicion is around the site CSS, but not sure.

Can someone help me figure what’s going on ? I had enabled the

array(


	'class'=&gt;'CWebLogRoute',


),

config element, but I didn’t see any relevant log message that might indicate any problem. Is there some other approach I must adopt in debugging this ?

cheers,

Jay

First of all …you need to clarify one thing here that where you are putting your images and css file.

Now to get the path for a images and css file from a application directory you have a two option.




$bUrl=Yii::app()->baseUrl; //base URL

$tUrl=Yii::app()->theme->baseUrl;



Depends on how you are managing your application.

NOTE: moved to proper section (General Discussion for Yii 1.1.x instead of Yii-powered applications)

Thanks for replying.

The image file is under <documentroot>/myappweb/images/

s.t. the baseUrl is <documentroot>/myappweb

How do you suppose I should use the $bUrl or $tUrl in the header ? As far as path is concerned, I’ve attempted several combinations of relative and absolute paths, though in my post I mentioned only 2, although can’t completely rule it out as a path issue.

Okay, thanks @mdomba. I think I was in the Yii-powered apps section, and mistakenly posted my query there. Shall take care next time.

Try this


<?php echo CHtml::image($bUrl."/images/image_name.jpg");?>

Don’t forget to initialise a $bUrl variable in a view file.

Perfect. It worked. Thanks a lot.

BTW, I am having a hard time ramping up on Yii, it is excruciatingly slow progress, maybe due to lack of php and general web-development background. Would love to hear if you’ve some suggestions on what might’ve worked for you, for learning Yii !

I’ve done the Blog tutorial, and the video tutorials. While the video tutorial was a breeze, the Blog tutorial has been not as smooth. I can understand what is being explained in each step, but still can’t piece the things together and create something useful on my own.

lol… :P …well i am also not a much experienced with yii…but in my initial days when i was also learning yii… i had a same thoughts… :)

But some sleepless night,late hours work and determination for learning yii make it possible for me…

So,Don’t worry you’ll be also get proficient soon…as much as you will spend time with it…Best of Luck…:)

Thanks Jayant ( BTW, we are namesakes, just realized! :slight_smile: )

I think the key, as you wrote, is really to keep the effort on and not give up (like most elegant yet difficult-at-first things). Slowly but surely, beginning to get a hang of it all. The thing that really is helping me a lot is, “Larry Ullman’s” tutorials series. He is a true teacher material. Lot of super smart people write excellent material for other super smart people, but you need a different kind of person to dumb-it-down for people not as smart :)

After reading his tutorials, switching back-n-forth between the User-Guide and Ref, things a getting lot clearer.

ohh that great… :)

And yes i do agree with you. “Larry Ullman’s” tutorials series is really a good reference site.But i spend my lots of time on the Yii documentation.that is why got lot of information about this framework.

Anyways,keep in touch. :)