Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 319
ThisWillDoIt Avatar asked Feb 20 '23 15:02

ThisWillDoIt


2 Answers

You can use the BaseUrl() View helper:

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

Then it should be fine...

like image 67
madflow Avatar answered Feb 22 '23 05:02

madflow


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();
like image 39
Oussama Jilal Avatar answered Feb 22 '23 06:02

Oussama Jilal