• missing xbfish.com image

CakePHP 1.2 favicon

missing xbfish.com image

* Update… The following guide will also works in CakePHP 1.3 :D

In CakePHP 1.2 default layout, favicon are linked through:

1
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">

The problem with this is that when you navigate to other views (except for the default controller and view it loads), the favicon will disappear. This is because the path to the favicon is lost.

There is also a mistake in CakePHP 1.2 Manual at here

The $html->meta has the wrong values fed into it and the parameters doesn’t match what the API desribe at here.

Hence, following the manual in CakePHP 1.2 will not works in displaying the favicon correctly. If we were to use $html->meta parameters as what it was describe in the API like below:

1
<?php echo $html->meta('icon', /favicon.ico'); ?>

We will get:

1
<link href="/favicon.ico" type="image/x-icon" rel="icon" />

The correct path is still not being generated !

To resolve this, we made use of $html->url from CakePHP 1.1 :

1
<?php echo $html->meta('icon', $html->url('/favicon.ico')); ?>

Now, the path of the favicon will be generated correctly and displayed in all views when using CakePHP 1.2

8 Comments

  • March 2, 2009 - 7:58 am | Permalink

    Thank you!

  • May 15, 2009 - 3:41 am | Permalink

    Hi,

    Thanks for the solution but for me the problem was solved with this code :

    $html->meta(‘icon’, $html->url(‘../img/favicon.ico’));

  • Tom
    January 10, 2010 - 2:39 am | Permalink

    Don’t forget to echo that
    meta(‘icon’, $html->url(‘/favicon.ico’)); ?>

  • Willie
    January 10, 2010 - 2:41 am | Permalink

    < ?= means echo in php :D

  • JEin
    May 28, 2010 - 6:07 am | Permalink

    I had to do this:
    echo $html->meta(‘/img/png’, ‘/img/favicon.png’, array(‘rel’ => ‘icon’));

  • May 28, 2010 - 11:11 am | Permalink

    @JEin

    Hey JEin, does my method no longer works?

  • VinBioDiesel
    January 2, 2011 - 3:43 am | Permalink

    Thanks! worked for me.. i was not able to display a favicon in views of PagesController.

    • January 2, 2011 - 12:37 pm | Permalink

      Yup, if you follow the api, you will find that your views of CakePHP will not display the favicon, except for the main page.

      I hope this helps you! The above guide also works in CakePHP 1.3 too!

  • Leave a Reply

    Your email address will not be published. Required fields are marked *

    *

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

    Spam protection by WP Captcha-Free