简体   繁体   English

在现有的Codeigniter hmvc应用程序中实现requirejs和客户端模板

[英]Implementing requirejs and client-side templating in existing codeigniter hmvc application

We have been working on a codeigniter hmvc project for quite sometime now and it has grown into a lot of back-end modules and controllers. 我们已经在一个代码点火器hmvc项目上工作了一段时间,它已经成长为许多后端模块和控制器。 For the front end we have been applying the regular jQuery and plugin approach along with inline scripting for Front end interaction and Ajax related tasks. 对于前端,我们一直在将常规jQuery和插件方法以及内联脚本应用于前端交互和Ajax相关任务。 Also we used HTML strings inside JS as our approach to templating. 另外,我们在JS中使用HTML字符串作为模板化方法。

But since now the application has gone big, we are in need to embrace the modular approach for our client side code along with implementing a build system for optimization of JS code. 但是自从应用程序变大以来,我们需要为我们的客户端代码采用模块化方法,并实现用于优化JS代码的构建系统。 During our research we found a few candidates that would help us start managing the code. 在研究过程中,我们发现了一些候选人,这些候选人将帮助我们开始管理代码。 We zeroes in on requirejs for dependency management and for templating we are considering on out of handlebars/moustache/dust.js. 我们将对requirejs进行依赖管理和模板处理归零,我们正在考虑不在handlebars / moustache / dust.js中使用。

However, it seems like most of the applications using require and templating are based on backbone and are basically one page web apps. 但是,似乎大多数使用require和tempulation的应用程序都是基于主干的,并且基本上是一页Web应用程序。 So, how do we implement the front end modularity and templating as a part of our already working (and growing) Codeigniter hmvc application ? 那么,如何将前端模块和模板实现为已经工作(并且正在不断发展)的Codeigniter hmvc应用程序的一部分?

RequireJS is a good choice for managing your code base. RequireJS是管理代码库的不错选择。 It's hard to give good advice regarding other technologies, it depends on your preferred coding style, needs and JavaScript expertise. 很难就其他技术给出好的建议,这取决于您喜欢的编码样式,需求和JavaScript专业知识。

Definitely compare different frameworks yourself and see which one is more comfortable. 一定要自己比较不同的框架,看看哪一个更舒适。 Some candidates include KnockoutJS, AngularJS, EmberJS. 一些候选人包括KnockoutJS,AngularJS,EmberJS。

And yes, you need to reference main.js in the data-main attribute of require.js script on every page (if you not creating single page app). 是的,您需要在每个页面上的require.js脚本的data-main属性中引用main.js(如果您未创建单页面应用程序)。 Think of it as an entry point into your program. 将其视为程序的入口点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM