我试图调用位于 ~/vendor/目录中的 javascript 函数(请参阅下面的架构),但没有成功。如果我将该 javascript 移动到我的目录 ~/public/js/,调用就会成功。
我相信我的问题可能来 self 的 .htaccess 文件,但尽管阅读了相当多的内容,我还是没有找到解决它的方法。如果有人能指出我正确的方向,我会很高兴。
这是目录结构(注意 root 和 public/中的 .htaccess):
<project name>/
application/
config/
controllers/
models/
views/
public/
css/
images/
js/ <- if placed here, the call succeeds
.htaccess
index.php
vendor/
<third-party code>/
javascript.js <- here, it doesn't
.htaccess
这是 .htaccess 文件的内容:
在根目录上:
<IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^$ public/ [L] RewriteRule (.*) public/$1 [L] </IfModule>
在公共(public)目录中:
<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?page=$1 [PT,L] </IfModule>
最佳答案
我建议:
public/js/Vendor
public/css/Vendor
或
public/Vendor/js
public/Vendor/css
将是最好的选择。我认为当您可以将 Vendor 文件夹添加到公共(public)文件夹时(我认为它应该去的地方),重写规则将是不好的做法。
关于javascript - 在MVC中使用第三方javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23561280/