Squadrons
Squadrons

Reputation: 2557

Cakephp - not loading css and js

I'm a rails developer doing some patchwork on a cakephp project.

I pulled from a repository and am trying to get a local version of the project up and running.

Right now, the application is trying to load assets from 'localhost/static/css'

The css is actually located in localhost/app-name/app/webroot/static/css.

I've renamed all the htaccess files (app-name/.htaccess, app/.htaccess, app/webroot/.htaccess) and commented them out, but the app is still looking for my assets at 'localhost/static/'.

What am I missing?

Thanks

Upvotes: 0

Views: 7094

Answers (3)

Sushil Kandola
Sushil Kandola

Reputation: 880

Don't remove .htaccess files. As in mine case I was facing same problem and now it's working fine.

Trick is simple, just ho to Apache directory, and open httpd.conf and search for rewrite_module and remove comment(#) from that line i.e.
#LoadModule rewrite_module modules/mod_rewrite.so will be
LoadModule rewrite_module modules/mod_rewrite.so

Upvotes: 2

RichardAtHome
RichardAtHome

Reputation: 4313

You need the .htaccess files!

Do you have mod_rewrite installed and enabled?

Do you have allow_override All set for your application webroot in you apache config? (So apache will read the CakePHP .htaccess files)

Did you clear the cache? (Remove all the files, but leave the directories in place in app/tmp - and make sure app/tmp is readable/writable by the webserver

Are you missing a symbolic link? I store my assets outside of webroot and symbolically link the directories (css, js, img, etc.) to /app/webroot

Upvotes: 2

Alessandro Minoccheri
Alessandro Minoccheri

Reputation: 35963

First you don't have to delete .htaccess and be sure that mod_rewrite is enabled into your localhost.
Second In cakephp there is a great helper called Html If you want to load a js try this into your view:

echo $this->Html->script('your_js.js');

this js have to be into your app/webroot/js

Instead for css try to use:

echo $this->Html->css('your_css.css');

Css have to be in this folder: app/webroot/css

cakephp have already its path but you have to respect convention

Upvotes: 1

Related Questions