Using a favicon in Zend Framework

What's the best way of handling a favicon.ico in Zend framework? I have seen alternatives that requires modification of phtml files like:

$this->headLink()->headLink(array('rel' => 'favicon',
                              'href' => '/img/favicon.ico'),

or modifications on .htaccess file.



Three choices:

  • Do nothing - if the favicon is named favicon.ico and sitting in your public directory, most browsers will pick it up
  • Hard-code the <link> tag into your layout
  • Programmatically add the link tag as in your code example

Personally I would go for option 2. There's little point programmatically adding the favicon if it will always be there. It might make sense if the favicon was different for different users, e.g. say your application had a themes system with different favicons for different themes, then you might want to use headLink().

Browsers tend to cache favicons for a long time, so as long as the link tag is appearing in your HTML source then it will eventually update. You can speed up the process by changing the filename, viewing the favicon directly in your browser and/or clearing your browser cache.

you just move the favicon.ico file into the folder public! ;)

I found that if rel attribute being "favicon" expected things not working, until i've change above attribute to "shortcut icon" (tested under Firefox 5.0 Ubuntu)

The ZF2 skeleton application includes a default favicon.ico at /public/img/favicon.ico. Just change that file and you're good to go.

Can also help to force the browser cache to refresh the file by pointing it to that file path explicitly.

//in controller
$this->view->headLink(array('rel' => 'shortcut icon', 'href' => '/themes/kieuhung/images/favico.png', 'type' => 'image/x-icon'), 'PREPEND');

//and in layout
echo $this->headLink();

good luck

Need Your Help

optimizing the 3 queries into one

php mysql sql

I am just trying to figure out on how to optimize the below sequence of queries into a single query.

Can traffic on loopback be packet sniffed?

networking tcp

Can any data exchanged on a local machine using the loopback IP (localhost) be packet sniffed if the PC is also connected to a network (wireless or landline)?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.