I started using Zend Framework and tried to add some stylesheets and javascript files like this in my layout.phtml:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>LoremIpsum</title>
<?php echo $this->headLink()->appendStylesheet('css/global.css'); ?>
</head>
The problem with this is, that it is only working if there is no action specified in the url. For example it works with this: www.domain.com, www.domain.com/index, www.domain.com/login
but if I add the action, even if it is www.domain.com/index/index it stops working.
I noticed that in this case the index.php is called twice and calls the ErrorController. But the output shows no error. It is the expected output just without the stylesheet information.
Any ideas what is wrong with my layout?
Edit 1:
Error Reporting is activated and works in other cases. HTML markup is correct. Firebug show that my css file wasn't found, but the path can't be wrong because without specified action it works correctly.
You can use the BaseUrl() View helper:
<?php echo $this->headLink()->appendStylesheet($this->baseUrl().'/css/global.css'); ?>
Then it should be fine...
If you want to see the erros, you will have to change your working envirement from production to developement (this is done by adding SetEnv APPLICATION_ENV development
to your .htaccess file)
About the layout randering twice, add this to the errorAction in the errorController file (make it the first line of the action) : $this->getResponse()->clearBody();
Edit :
Ok, Try this for appending the stylesheet instead :
$this->headLink()->appendStylesheet('css/global.css');
echo $this->headLink();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With