Thematic asset does not work in CakePHP 2.2.4

I saw a lot of questions regarding the link to themed resources in CakePHP, and none of them solves my problem, and the last post was in 2012, so I thought that I would post my question there.

I applied themes in my CakePHP 2.2.4 application. My theme called "default" (previously called "default" up to 1 minute ago) is in app/View/Themed/default (previously the theme name also had a corresponding D header for the folder name).

My css file is in app/View/Themed/default/webroot/css/style.css , which I call in app/View/Themed/default/Layouts/default.ctp with the following code

Layout Default.ctp

 echo $this->Html->css('style'); 

(I tried to use the capital W for webroot "just in case", but it is not surprising that this did not work)

I have included this link in my AppController to establish which theme I am using. All view files point to the correct topic, but the problem is right now with the stylesheet (I still need to interact with other resources such as js or image files).

Appcontroller

 class AppController extends Controller { public $theme = 'default'; // previously 'Default' // also, have used both 'public $theme' and 'var $theme', no difference 

I read the following questions and none of the “solutions” worked. Most of the solutions were spell checking / capitalization, checking folder permissions, checking my .htaccess file, etc. Still nothing. And new ideas?

.htaccess

 <IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^$ app/webroot/ [L] RewriteRule (.*) app/webroot/$1 [L] </IfModule> 

Folder permissions for web pages and css folders of theme 755.

Here are some resources that I used with no luck.

http://book.cakephp.org/2.0/en/views/themes.html

CakePHP Theme Resource Error

Unable to retrieve css and image files in cakephp websites web troll folder

https://groups.google.com/forum/#!topic/cake-php/xaRAugMoNSc

CakePHP 2.x theme not working

https://groups.google.com/forum/#!topic/cake-php/siYVWchUb1g

UPDATE: using $this->Html->image('image.jpg') , correctly displays a specific image located in View/Themed/Default/webroot/img/image.jpg . However, using $this->Html->css('style') trying to pull the stylesheet from app/webroot/css/style.css , not from app/View/Themed/default/webroot/css/style.css . I also had to change the theme name and the folder name of my theme to "Default" with an uppercase letter D to get the correct image. The stylesheet is still incorrectly linked. If I go directly to my theme stylesheet in the browser, a blank page will appear. If I go to a stylesheet that does not exist in my theme folder, then I get the correct error message. However, viewing the source of my theme stylesheet (the one that exists) shows a blank page.

+8
cakephp themes assets
source share
4 answers

Well, maybe this is obvious ... but my stylesheet uses the functions that I created in the user assistant. When the stylesheet is in app/webroot/css , the problem does not occur, but when the stylesheet is in app/View/Themed/Default/webroot/css , it cannot be displayed correctly and therefore Cake links to a nonexistent stylesheet that should be in app/webroot/css . I removed helpers from my theme stylesheet, and now everything works.

I also returned the theme name from "default" to "Default" so that the images would display correctly using $this->Html->image (and presumably the stylesheet and JS files), even if the view files were correctly linked, regardless of capitalization.

+1
source share

CakePHP uses the CamelCase convention. Try changing the name of your topic, for example. default to default . It happened to me.

My topic was called megaecia , but there was no error message, nothing was in the log (because I was windows, it didn’t happen on unix), then I changed to megaecia and everything works successfully.

Hope I helped.

+3
source share

The asset files for this theme should be placed in the app/webroot/theme folder as follows:

 app/webroot/theme/default/css app/webroot/theme/default/js app/webroot/theme/default/img . . . 

Where default is the name of the topic, starting with a lowercase letter. The theme folder name is hard-coded. Note: the -ed suffix is ​​missing.

Thematic layouts should be placed in the app/View/Themed/Default/Layouts folder. The topic title should respect the CamelCase rule, as Gabriel Dook replied. Actually, I had a problem when CakePhp could not find my layout on the Linux machine because I named the folder with the theme in lower case, for example app/View/Themed/Default/Layouts .

And one more thing: lowercase letters should be indicated in the controller theme: $this->theme = 'default'; . This affects the search for assets, since we placed our resources in the lower folder app/webroot/theme/default .

0
source share

If you are trying to access the CSS resource from a subdirectory of your theme website, be sure to add / at the beginning.

i.e.

 $this->Html->css('/plugins/bespoke.css'); 

This will call CSS from the themes directory.

if you did not add / at the beginning, the cake will not look for the theme folder, instead it tries to load CSS from your application’s default webroot directory

0
source share

All Articles