我正在尝试在Zend框架中应用css。我的css文件在public/css/layout.css
。首先,我在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');
}
指定要使用的标题和样式表。然后在layout.phtml
中添加以下代码:
<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>
简单地添加bootstrap.php
中指定的样式表的链接。
但是当我运行项目,然后我得到没有css的形式。为什么会这样?当我在Mozilla浏览器中使用Firebug检查css时,它显示:
<h3>Exception information:</h3>
<p>
<b>Message:</b> Invalid controller specified (css) </p>
<h3>Stack trace:</h3>
<h3>Request Parameters:</h3>
<pre>array (
'controller' => 'css',
'action' => 'layout.css',
'module' => 'default',
) </pre>
请帮我解决这个问题
Try
$view->headLink()->prependStylesheet('/css/layout.css');
您的/public/。htaccess吗?
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
如果你没有前4行,这个文件会将你的请求"css/layout.css"重定向到index.php,然后Zend会将其解释为controller ->动作的链接。
如果您有这个文件,请确保您的服务器上启用了mod_rewrite。
你应该把你的链接写成"akond"。
祝你好运=)
这对我很有帮助:
Zend_Controller尝试执行我的样式表作为控制器
(更新)好的,只是添加以下行到我的。htaccess文件,现在一切正常工作…
RewriteRule !.(js|ico|txt|gif|jpg|png|css|htc|swf|htm)$ index.php
但后来我发现了这个
http://devzone.zend.com/1651/managing-css-and-javascript-files-within-a-zend-framework-app/