javascript - 在MVC中使用第三方javascript

标签 javascript php .htaccess mod-rewrite

我试图调用位于 ~/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/

相关文章:

.htaccess "Options not allowed here"

javascript - 从原生 ios 代码调用 javascript 函数(位于参数中)

javascript - 返回 JS 中的今天日期

javascript - 自动刷新页面中嵌入的 Google 图表的最简单方法

php - 处理来自多个国家/地区的地址输入的最佳方式是什么?

javascript - 当处理请求发布ajax时,如何禁用此表单中的表单(用户无法检查、填充文本、选择下拉列表等)?

php - 如何让 .htaccess 在不知道参数名称的情况下传递所有 GET 参数?

php - Magento产品页面上的ERR_TOO_MANY_REDIRECTS

javascript - Materialise CSS on chip 删除

javascript - 如何使用 selenium 驱动程序单击元素?