Set favicon for Zend Framework

I think below is the decent/ZF way to do it:


//application/Bootstrap.php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initView()
{
// Initialize view
$view = new Zend_View();
$view->doctype('XHTML1_STRICT');
$view->headLink()->headLink( array( 'rel' => 'favicon',
'href' => $view->baseUrl( 'favicon.ico' ),
'type' => 'image/x-icon' ));
// Add it to the ViewRenderer
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper(
'ViewRenderer'
);
$viewRenderer->setView($view);
// Return it, so that it can be stored by the bootstrap
return $view;
}
}

And in head portion of the layout file( application/layouts/scripts/layout.phtml ):

<?php echo $this->headLink()?>

Shall be aware that there may exist a better way.

English

Comments

it doesn't work for me. I still see the default zend icon..

Please note, in code of this line

'href' => $view->baseUrl( 'favicon.ico' ),

the "favicon.ico" file should be located at folder: /application_root_path/public/
The file tree should look like below:

|-- application
| |-- Bootstrap.php
| |-- configs
| | `-- application.ini
| |-- controllers
| | `-- IndexController.php
|-- library
| |-- Zend
| `-- ZendX
|-- public
| |-- css
| | `-- global.css
| |-- favicon.ico
| |-- images
| |-- index.php
| `-- js
.........

If the file location is right, then you may want to clear the cache of your browser for a try.

Add new comment