为什么使用CakePHP的JsHelper? [英] Why use CakePHP's JsHelper?

查看:178
本文介绍了为什么使用CakePHP的JsHelper?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚从CakePHP开始,并想知道是否有人可以解释使用其JsHelper超越编码常规静态jQuery和JS的真正好处。到目前为止,我还没有真正看到帮助者如何使创建脚本更容易或更快。

I'm just starting with CakePHP and was wondering if someone could explain the true benefit of using its JsHelper over coding regular static jQuery and JS. So far, I don't really see how the helper would make creating scripts easier or faster.

推荐答案

写了我的GoogleMaps Helper;)
基本的想法是,你可以使用与应用程序的其余部分相同的语言(php在这种情况下),你可以传入任何php选项数组和数组持有数据值和帮助应该是蛋糕的照顾。

for the same reason I wrote my GoogleMaps Helper ;) the basic idea is that you can use the same language (php in this case) as the rest of the application and you can pass in any php option arrays and arrays holding data values and the helper is supposed to cake care of it.

它类似于cakephp作为php的包装。它包装你的代码,并可以帮助保持干燥。

it is similar to cakephp as a wrapper for php. it wraps your code and can help keep it dry.

不要弄错我从来没有使用过js / ajax助手自己。
但是我可以理解为什么有些人想选择它来编写JS自己。
在某些情况下,输出甚至可以更正确(如果你不知道潜在的问题)。例如IE错误:
如果你自己输出{}选项,忘记删除最后一个,它不会运行在IE6等,不能发生与帮助作为包装器 - 至少它shoudnt;)

don't get my wrong - i never ever used the js/ajax helper myself. but I can understand why some want to chose it over writing JS themselves. in some cases the output can even be more "correct" (if you don't know about the potential problems). for example the IE bug: if you output {} options yourself and forget to remove the last , it will not run in IE6 etc. that can't happen with the helpers as wrapper - at least it shoudnt ;)

所以与帮助程序,它不运行或作为一个熟练的开发人员团队运行设计它的工作。
特别是对于不那么熟练的开发人员这通常是双赢的情况:快速和可靠。你可以随时开始切换到手动的东西(如果你看到实际的JS输出并开始理解它)。

so with the helper it either doesnt run at all or runs as a team of skilled developers designed it to work. especially for not so skilled developers this is usually a win-win situation: fast and more reliable. you can always start to switch to manual stuff later on (if you see the actual JS output and start to understand it).

也 - 当任何js方法需要为了某种原因改变你的使用帮助方式通常不会。如果你不使用抽象,你可能会发现自己需要手动调整所有出现。

also - when any of the js methods need to change for some reason your way of using the helper usually doesn't. if you don't use the abstraction you might find yourself in the need to manually adjust all occurrences.

这篇关于为什么使用CakePHP的JsHelper?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆