Search code examples
cakephpcakephp-1.3favicon

cakephp 1.3 favicon


I am using cake 1.3 and i had tried to implement favicon..But some strang error happens and sometime its showing favicon but for sometimes its not showing it.Pronlem is cakephp img folder path is changing>How can i escape from this problem.

i have used below code in my default.ctp

<?php echo $this->Html->meta('favicon.ico','../../app/webroot/img/favicon.ico',array('type' => 'icon'));?> 

Favicon shows for following url.

http://localhost/finalportal/index.php/events/eventlist

Favicon not showing for followin url

http://localhost/finalportal/index.php/productsServices

I had tried this also.

<?php echo $this->Html->meta('favicon.ico',/favicon.ico',array('type' => 'icon'));?> 

in this case favicon path is not correct

What i am doing wrong


Solution

  • The problem in the first version is that you're using relative paths so it will always end up pointing to the wrong place, depending on how many parameters the URL has. ../../app/webroot means "two levels down, then to directory app/webroot". Two levels down from http://localhost/finalportal/index.php/events/eventlist is http://localhost/finalportal/index.php/, but two levels down from http://localhost/finalportal/index.php/productsServices is http://localhost/finalportal/, so you end up in the wrong place.

    The reason why the second method (which is syntactically correct) doesn't work is probably because you have the server set up wrong. Apache's DocumentRoot should point at the app/webroot directory or the .htaccess file in the root directory should redirect requests to app/webroot.