CakePHP theme resources return error

2019-08-29 05:39发布

问题:

I've never had problems with CakePHP's theming system in the past, but now, errors galore. My main issue is that all theme resources (those in /app/views/themed/MyTheme/webroot/*) fail to load. I've set up a custom AppController in /app to set the theme.

var $view = "Theme";
var $theme = "MyTheme";

When I go to any page, I can see that it's utilizing my theme's default.ctp layout and the HTML is fine. Any and all page resources, CSS, JavaScript, images, anything in the theme webroot, fails to load and instead gives me an error like the following (let's say I tried to access http://example.com/theme/MyTheme/img/bg.png):

Error: ThemeController could not be found.

Error: Create the class ThemeController below in file: app/controllers/theme_controller.php

<?php
class ThemeController extends AppController {

    var $name = 'Theme';
}

I've never received an error like this in my time with CakePHP. I'm running the latest stable version at 1.3.7.

回答1:

I've finally found a solution. CakePHP didn't like my uppercase theme name. In fact, any theme name that I tried that included uppercase characters failed to work. I changed my folder name and internal theme name from "MyTheme" to "my_theme" and it worked perfectly. Could possibly be a bug, but it could be undocumented, yet expected functionality.