2

I am trying to apply css in the Zend Framework. My css file is in public/css/layout.css. First of all I added the following code lines in bootstrap.php:

protected function _initPlaceholders()
 {
   $this->bootstrap('View');
   $view = $this->getResource('View');
   $view->doctype('XHTML1_STRICT');

   // Set the initial title and separator:
   $view->headTitle('My Site')
        ->setSeparator(' :: ');

   // Set the initial stylesheet:
   $view->headLink()->prependStylesheet('../../css/layout.css');
 }

Which simply specifies the title and stylesheet to be used. Then in layout.phtml I add the following code:

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<?php
echo $this->headTitle();
echo $this->headScript();
// add a link to the site style sheet
echo '';
echo $this->headLink();

?>
</head>

Which simply adds link of the stylesheet specified in bootstrap.php.

But when I run the project then I am getting the form without css. Why is this? When I check the css with Firebug in a Mozilla browser it says:

<h3>Exception information:</h3>
<p>
<b>Message:</b> Invalid controller specified (css) </p>
<h3>Stack trace:</h3>
<h3>Request Parameters:</h3>
<pre>array (
   'controller' =&gt; 'css',
   'action' =&gt; 'layout.css',
   'module' =&gt; 'default',
 ) </pre> 

Please help me out to resolve this issue.

1
  • Accept answers to your previous questions and you might get some help in return Commented Dec 12, 2011 at 14:48

3 Answers 3

3

Try

$view->headLink()->prependStylesheet('/css/layout.css');

this should help.

Sign up to request clarification or add additional context in comments.

Comments

3

Do you have this code on your /public/.htaccess file?

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

If you don't have the first 4 lines, this file will redirect your request of "css/layout.css" to index.php and then, Zend will interpret it as a link for a controller -> action.

If you have this file, make sure that mod_rewrite is enabled on your server.

And you sould put your link as "akond" said.

Good luck =)

2 Comments

.htaccess file contains the above lines and rewrite module is enabled on server also as in httpd.conf I have uncommented the line LoadModule rewrite_module modules/mod_rewrite.so But still same problem.
Can you access the css file with a direct link? Example: mydomain.com/css/layout.css? Or does it returns the same thing that firebug reports?
0

This helped me:

Zend_Controller tries to execute my stylesheets as controller

[update]

Ok, just added the following line to my .htaccess file and all works as expected now...

RewriteRule !.(js|ico|txt|gif|jpg|png|css|htc|swf|htm)$ index.php

but then I found this one:

http://devzone.zend.com/1651/managing-css-and-javascript-files-within-a-zend-framework-app/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.