ryan
ryan

Reputation: 333

Invalid controller specified (css) in Zend framework

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.

Upvotes: 2

Views: 2550

Answers (3)

Krzysztof Boduch
Krzysztof Boduch

Reputation: 715

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/

Upvotes: 0

Cristiano Santos
Cristiano Santos

Reputation: 2137

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 =)

Upvotes: 3

akond
akond

Reputation: 16035

Try

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

this should help.

Upvotes: 3

Related Questions