1

我在 CakePHP 中有一个奇怪的问题。

我使用一个主题,所以我有一个文件夹 Themed/mytheme ,在这种情况下我有Themed/mytheme/webroot/img/

我担心的是,在这张文件图片中,我有几张图片。到目前为止,我所有的图像都显示在 url 中/theme/mytheme/img/myimage.png

今天早上我创建了另一个图像,所以我保存在这个文件夹 img 中并且有问题。当我想显示我的图像时,出现以下错误:

missing Controller
Error: ThemeController could not be found.

Error: Create the class below in ThemeController file: app \ Controller \ ThemeController.php

<? php
ThemeController class extends AppController {

}
Notice: If you want to customize this error message, create app \ View \ Errors \ missing_controller.ctp

Stack Trace
APP \ webroot \ index.php line 92 → Dispatcher-> dispatch (CakeRequest, CakeResponse)

我的错误是其余的图像不在同一个文件夹中。

你能告诉我或者它可能来自请吗?

谢谢你。

PS:对不起我的英语。

4

1 回答 1

1

网址有错别字

Cake 的默认 mod 重写规则是:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule ^ index.php [L]
</IfModule>

这意味着如果 url 不匹配目录并且不匹配文件 - 将请求发送到 CakePHP。由于您的请求正在由 CakePHP 处理 - 您请求的路径与您创建的文件不同。

不要硬编码主题路径

要得到这样的错误,视图文件中似乎很可能有这样的代码:

echo $this->Html->image('/theme/ThemeName/img/foo.png');

这不是必需的,这样做会导致问题——比如路径错误,以及请求不存在的文件。相反,只需使用:

echo $this->Html->image('foo.png');

如果当前请求是针对主题的 - 如果存在,Cake 将自动使用/theme/ThemeName/img/foo.png/img/foo.png如果不存在。

于 2013-04-15T21:49:13.223 回答