这是我想要的结构:
-webroot/
-css/
-font/
-img/
-js/
-new_folder/
-file.css
-another_new_folder/
-file.js
如何访问 .ctp
文件内的 webroot/new_folder/file.css
和 webroot/new_folder/another_new_folder/file.js
,为了生成这样的两个标签:
<link href="/new_folder/file.css">
<script src="/new_folder/another_new_folder/file.js">
如果可能的话,不生成 Controller 。
谢谢大家。
最佳答案
你可以使用
echo $this->Html->css('/new_folder/file');
// webroot/new_folder/file.css
echo $this->Html->script('/new_folder/another_new_folder/file');
// webroot/new_folder/another_new_folder/file.js
对于CSS和脚本,您可以使用以下方式
echo $this->Html->script('custom');
// webroot/js/custom.js
echo $this->Html->script('otherdir/custom');
// webroot/js/otherdir/custom.js
echo $this->Html->script('/otherdir/custom');
// webroot/otherdir/custom.js
关于javascript - cakePhp - 访问 webroot 内的文件夹内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45875504/