ThisWillDoIt
ThisWillDoIt

Reputation: 509

Append stylesheet with Zend Framework only works if no action is specified

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.

Upvotes: 4

Views: 4602

Answers (2)

madflow
madflow

Reputation: 8480

You can use the BaseUrl() View helper:

<?php echo $this->headLink()->appendStylesheet($this->baseUrl().'/css/global.css'); ?>

Then it should be fine...

Upvotes: 7

Oussama Jilal
Oussama Jilal

Reputation: 7739

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();

Upvotes: 1

Related Questions