Using the icon in the Zend Framework

What is the best way to handle favicon.ico within Zend? I have seen alternatives that require modification of phtml files, such as:

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

or changes to the .htaccess file.

Thanks,

+6
source share
5 answers

Three options:

  • Do nothing - if favicon is called favicon.ico and sits in your public directory, most browsers will pick it up.
  • The hardcode of the <link> in your layout
  • Programmatically add a link tag, as in your code example

Personally, I would go for option 2. There is little point in programmatically adding an icon if it is always there. This may make sense if the icon was different for different users, for example. let's say your application has a theme system with different icons for different themes, then you can use headLink ().

Browsers typically cache badges for a long time, so as long as the link tag appears in your HTML source, it will eventually be updated. You can speed up the process by changing the file name, viewing the icon in your browser and / or clearing the browser cache.

+5
source

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

+3
source

I found that if the rel attribute is an “icon”, the expected things do not work until I change the attribute above to a “shortcut” (tested under Firefox 5.0 Ubuntu)

+1
source
 //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(); 

luck

+1
source

The ZF2 skeleton contains favicon.ico by default in /public/img/favicon.ico . Just change this file and you are good to go.

It can also help make the browser cache update the file by explicitly pointing it to this path.

0
source

Source: https://habr.com/ru/post/891103/


All Articles