Zend_Controller 尝试作为控制器执行我的样式表

发布于 2024-11-15 21:32:38 字数 1564 浏览 4 评论 0 原文

我按照 此处

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

    $view->doctype('XHTML11');

    $view->headTitle('Foo Bar Title')
         ->setSeparator(' :: ');

    $view->headMeta()->appendHttpEquiv(
        'content-type',
        'application/xhtml+xml; charset=UTF-8'
    );

    $view->headMeta()->appendName('robots', 'index,follow');

    $view->headLink()->appendStylesheet('/styles/styles.css', 'screen')
                     ->appendStylesheet('/styles/print.css', 'print');
}

呈现的 HTML 看起来是正确的。

<title>Foo Bar Title</title>
<link href="/styles/styles.css" media="screen" rel="stylesheet" type="text/css" />
<link href="/styles/print.css" media="print" rel="stylesheet" type="text/css" />
<meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
<meta name="robots" content="index,follow" />

但是 CSS 没有正确加载,因为 Zend_Controller 认为它是一个控制器或其他东西。当我尝试打开 CSS 文件时,出现以下错误:

致命错误:未捕获的异常 'Zend_Controller_Dispatcher_Exception' 带有消息“无效控制器” 指定(错误)'

有任何提示吗?

[更新]

好的,只需将以下行添加到我的 .htaccess 文件中,现在一切都按预期工作...

重写规则 !.(js|ico|txt|gif|jpg|png|css|htc|swf|htm)$ 索引.php

I initialize my placeholders for my global layout within the Bootstrap.php as described here.

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

    $view->doctype('XHTML11');

    $view->headTitle('Foo Bar Title')
         ->setSeparator(' :: ');

    $view->headMeta()->appendHttpEquiv(
        'content-type',
        'application/xhtml+xml; charset=UTF-8'
    );

    $view->headMeta()->appendName('robots', 'index,follow');

    $view->headLink()->appendStylesheet('/styles/styles.css', 'screen')
                     ->appendStylesheet('/styles/print.css', 'print');
}

The rendered HTML looks correct.

<title>Foo Bar Title</title>
<link href="/styles/styles.css" media="screen" rel="stylesheet" type="text/css" />
<link href="/styles/print.css" media="print" rel="stylesheet" type="text/css" />
<meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
<meta name="robots" content="index,follow" />

But the CSS doesn't get loaded correctly because Zend_Controller thinks it's a controller or something. When I try to open the CSS files the following error occurs:

Fatal error: Uncaught exception
'Zend_Controller_Dispatcher_Exception'
with message 'Invalid controller
specified (error)'

Any hints?

[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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请持续率性 2024-11-22 21:32:38

典型的 Zend 项目布局看起来像这样:

.
|-- application
|   |-- Bootstrap.php
|   |-- configs
|   |-- controllers
|   |-- forms
|   |-- layouts
|   |-- models
|   `-- views
|-- library
`-- public
    |-- images
    |   `-- favicon.ico
    |-- index.php
    |-- js
    |   `-- scripts.js
    `-- styles
        `-- style.css

你的看起来相似吗?具体来说,您的 public 文件夹(而不是应用程序文件夹)下是否有 CSS 和 JavaScript 文件?如果是这样,您可以检查文件权限吗?

另外,我建议检查文件权限。如果 Apache 进程无法读取 CSS 文件,那么 Apache 将无法为它们提供服务。

A typical Zend project layout looks something like this:

.
|-- application
|   |-- Bootstrap.php
|   |-- configs
|   |-- controllers
|   |-- forms
|   |-- layouts
|   |-- models
|   `-- views
|-- library
`-- public
    |-- images
    |   `-- favicon.ico
    |-- index.php
    |-- js
    |   `-- scripts.js
    `-- styles
        `-- style.css

Does yours look similar? Specifically, do you have CSS and JavaScript files somewhere under the public folder (and not the application folder)? If so, can you review file permissions?

Also, I recommend reviewing file permissions. If the CSS files aren't readable by the Apache process, then Apache won't be able to serve them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文