Favicon

Ok just starting out with Yii but getting frustrated already since I can’t get my favicon to show up. Can someone point me in the right direction please?

Set it in views/layouts/main.php

Sorry should have included that. I am using that file.

More info.

I am using XAMPP on MAC and on initial load of a website it displays the XAMPP favicon. When I change it to mine is then displays the default browser favicon. Maybe XAMPP is causing me these problems since apparently I am modifying the correct file. I will test in another environment.

In main.php file in layouts, you can use meta tag to set the favicon location

You can use script like this at layouts/main.php


<!-- put in head tag -->

<link rel="shortcut icon" href="<?php echo Yii::app()->request->baseUrl; ?>/favicon.ico" type="image/x-icon" />

Locate your favicon.ico (name of file ico) in your root web directory.

I did it, and you should wthout any problem. ;D

I just read this post it worked!

Thank you very much sir!

Summary favicon.ico issue.

  1. You can use your own icon file, not have to named as favicon.ico, and not have to in the web site root directory. You have to claim your icon file in your page’s head section. In Yii framework, the page head normally in ./protected/views/layouts/main.php

<?php /* @var $this Controller */ ?>

<head>

	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

	<meta name="language" content="en" />

...

	<link rel="shortcut icon" href="<?php echo Yii::app()->request->baseUrl; ?>/images/myCompanyLogo.ico" type="image/x-icon" /> 

	<title><?php echo CHtml::encode($this->pageTitle); ?></title>

</head>



  1. If you are using Windows, you can use "Paint" to create icon file. You may wonder there is no this type when you save as. In a short word, icon file is 16X16 16 color bitmap, or 32X32 256 color bitmap. So the simple way to create your company log icon file is open your company log file in "Paint", resize to 16X16 pixels, then save as 16 color bitmap. Once it saved, changed the file name extension from .bmp to .ico. Done.

Great! Thank you!

Got the same problem. Above solutions helped. Thanks.

@Johnny Gan it’s work for me. Thank you so much sir. :)