模块化扩展 CI 锚定资产

发布于 2024-11-14 21:16:35 字数 256 浏览 7 评论 0原文

因此,我正在制作一个 CMS,并使用模块化扩展 HMVC CI 2.0。很可爱。我想知道保持我的资产(js、css、img)与模块目录中的模块相关的正确方法。

问题是,我如何链接到这些资产?假设我正在使用模板引擎并传递 js 文件来加载特定页面:

$js[] = 'assets/js/my_js.js';

我想我问的都是错误的,但是有没有一种简单的方法可以使用当前模块的目录进行链接?

提前致谢。

So, I'm making a CMS at the mo, and using the modular extensions HMVC CI 2.0. It's lovely. I'm wondering the correct method for keeping my assets (js, css, img) related to a module within the module directory.

The problem being, how do I link to these assets? Let's say I'm using a template engine and passing the js files to load for a specific page:

$js[] = 'assets/js/my_js.js';

I suppose I'm asking this all wrong, but is there an easy way to link using the current module's directory?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

少女七分熟 2024-11-21 21:16:35

目前 CI 或 HMVC 中没有为此构建任何内容。

我更喜欢引用允许从应用程序目录中直接访问的文件,例如 images/js/css。主要是因为:

  • 我不想让任何人知道我的应用程序的内部结构。通过直接从模块内引用文件,您可以公开应用程序的目录结构。

  • 如果我使用HMVC,我永远不会这样做

  • 你必须现在允许通过 .htaccess 直接访问应用程序内的(某些)目录。出于安全原因,我宁愿简单地禁止整个事情。

我理解尽可能模块化的愿望,但对我来说,这不值得这么麻烦。我更喜欢在名为“modules”的公共文件夹中保留一个单独的目录(复制我的应用程序/模块结构),其中除了“assets”(css、js、images...)之外什么都没有。

我会提供一些代码,但我不知道如何将 js/css 添加到视图中 - 它可能与我的方式有很大不同。编写一个函数来检测当前模块、控制器或方法并自动更改资产文件夹是很容易的,但这可能会干扰其他共享资产。我建议编写一个完全独立的函数来从模块加载资源。

There's nothing currently built in to CI or HMVC for this.

I prefer not to reference files that are allowed direct access, like images/js/css, from within the application directory. Mainly because:

  • I don't want anyone to know what the guts of my app look like. By referencing files from directly within a module, you expose your application's directory structure.

  • I would never do this if I weren't using HMVC

  • You must now allow direct access to (certain) directories within the application via .htaccess. For security reasons, I prefer to simply disallow the entire thing.

I understand the desire to be as modular as possible, but to me it's not worth this hassle. I prefer to keep a separate directory in a public folder called "modules" (duplicating my application/modules structure), that has nothing but "assets" (css, js, images...).

I'd offer some code but I have no clue how you are adding js/css to your views - it's probably much different than the way I do it. It would be easy enough to write a function to detect the current module, controller, or method and change the asset folder automatically, but this may interfere with other shared assets. I'd suggest writing an entirely separate function for loading assets from modules.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文