Where Appropriate to Allocate Javascript and CSS Libraries in Cakephp 3

Asked

Viewed 222 times

2

What is the appropriate location to allocate libraries and plugins Javascript and CSS in Cakephp 3, as there has been a major change in the directory structure from this release to earlier.

All files .js and .css has a specific and separate location.

All file calls are made this way ():

<?= $this->Html->css('style.css') ?>
<?= $this->Html->script('main.js',['defer' => true]) ?>

Soon it is possible to notice that there is presumption of the directory where the files are.

Directory structure (I took prints to see 100% of the structure and what is inside each):

inserir a descrição da imagem aqui

OBS: Plugins and Libraries like Jquery, Jquery-ui and Bootstrap have folders and subfolders, font files, icons, images, javascript and css.

  • Usually the front end goes on public, www, webroot and so on.

  • @gmsantos and what would be the references?

  • Cakephp does this by rewriting .htaccess. Probably, css/default.css would point to app/webroot/css/default.css

  • 1

    @I don’t know the methods Html->css() cake, when I get a little time here, I’ll look it up on the Docs. What I do is map in apache the webroot folder as root and in the files reference the relative path, which would be css/default.css

1 answer

1


You should put it in the folder webroot of its application, taking into account that the path pointed to the css or js would be declared without "webroot"

Example:

In html css/default.css points to the directory webroot/css/default.css

See Cakephp 3’s . htaccess code to be more sure:

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

https://github.com/cakephp/app/blob/master/.htaccess

  • and what would the statement look like: <?= $this->Html->css('style.css') ? > this points to a loose file inside the css folder that is inside the webroot, as it would look to Lingar a css from the bootstrap lib?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.