PHP框架应该生成JavaScript吗? [英] Should PHP frameworks generate JavaScript?

查看:60
本文介绍了PHP框架应该生成JavaScript吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到了一个PHP框架; Zend Cake Symfony ;似乎要么生成JavaScript,要么允许它作为字符串嵌入PHP本身。这是一个好主意吗?对于那些使用过这些框架/库的人来说,使用Ajax和JavaScript助手的经验是什么?它易于维护吗?它是否缩短了开发时间?

I've noticed that a PHP frameworks; Zend, Cake, and Symfony; seem to either generate JavaScript or allow it to be embedded as a string into the PHP itself. Is this a good idea? From people who've used these frameworks/libraries, what has been your experience working with the Ajax and JavaScript helpers? Has it been easy to maintain? Does it cut down on development time?

推荐答案

不是一个坏主意,

生成的javascript通常意味着如果没有它,网站将无法运行(就像许多asp.net网站一样)。如果你想做更复杂的事情或想要增强可访问性,除了从CSS和Javascript清楚地分离HTML之外别无他法。

Generated javascript usually means that the site won't even function without it (like many asp.net sites). If you want to do more complex things or want to enhance accesibility there is no other way around than clearly seperating HTML from CSS and Javascript.

分离Javascript也会使你的代码更多可维护,因为你不需要让你的客户端前端开发人员搞乱你的PHP代码和反过来。

Seperating Javascript also makes your code more maintainable as you do not need to have your client side frontend developers mess with your PHP code and the other way around.

使用Javascript的最好方法是首先让php生成您的html,然后在该页面的底部包含您的javascript文件并使用onDomReady等功能。这也不会强迫您使用特定的库只是因为您的框架使用它作为其生成的Javascript的基础。

The best way to use Javascript is to first let php generate your html, then at the bottom of that page include your javascript files and use functionality like onDomReady. This also doesn't force you to use a particular library just because your framework is using that as base for its generated Javascript.

这篇关于PHP框架应该生成JavaScript吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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