mtpultz
mtpultz

Reputation: 18268

CakePHP 2.4.1 $this->webroot gives / and not /app/webroot

I've inherited a CakePHP 2.4.1 project and I don't want to use all the html, css, script helpers as it is make the app more dependent on CakePHP if we ever wanted to change frameworks, but when I try to load scripts, styles, images using

<?php echo $this->webroot; ?>css/app.min.css

but that produces a URL of

http://example.com/app.min.css

$this->webroot just returns /, I'm not very familiar with CakePHP yet. Is there a configuration setting or something that is set that is changing this? My vhosts file is pointed at webroot.

Upvotes: 0

Views: 215

Answers (1)

Ohgodwhy
Ohgodwhy

Reputation: 50787

The "Webroot" is the directory that is accessible to the public. It contains all of your asset elements, etc, it should look like:

-- webroot
| -- assets
    | -- css
    | -- js
    | -- img
| -- index.php
//etc

So when you run $this->webroot you are getting the path to your public directory. This assumes that all asset files will reside in this directory.

In the event that this has been modified, simply open up the index.php of your application and find this line:

define('WEBROOT_DIR', 'MY_WEBROOT_DIR');

And change MY_WEBROOT_DIR to the actual name of your public directory as it resides within your CakePHP Application

Upvotes: 1

Related Questions