PHP:分离业务逻辑和表达逻辑,值得吗? [英] PHP: Separating Business logic and Presentational logic, is it worth it?

查看:103

这种做法不仅使代码外观清洁剂,它也有许多长期和短期的好处。

组织代码永远不会出错。首先,如果其他人不得不在你之后继续阅读,那么维护起来就容易多了,而且阅读起来也更容易。我之前和Smarty一起工作过,它很好,它可以让设计人员避免干扰程序代码。

使用模板系统和框架可以更容易地完成任务。你可以遵循的经验法则是DRY(不要重复自己)。框架可帮助您实现此目标。



您可能需要查看 MVC ,这是这些框架基于的模型。但是你可以实现这个设计结构,而不必使用框架。避免学习曲线。对于像 Zend 这样的框架,学习曲线比其他一些框架要大得多。



我发现代码点火器非常易于使用,并且它们有一些非常有用的视频教程他们的网站。



祝你好运!


Possible Duplicate:
Why should I use templating system in PHP?

I was just curious as to how many developers actually do this?

Up to this time I haven't and I was just curious to whether it really helps make things look cleaner and easier to follow. I've heard using template engines like Smarty help out, but I've also heard the opposite. That they just create unnecessary overhead and it's essentially like learning a new language.

Does anyone here have experience with templates? What are your feelings on them? Are the helpful on big projects or just a waste of time?

On a side note: The company I work for doesn't have a designer, there are just two developers working on this project charged with the re-design/upgrade. I also use a bit of AJAX, would this have issues with a template engine?

解决方案

Not only does this practice make the code look cleaner, it also has many long term and short term benefits.

You can never go wrong with organizing code. First off it makes it much easier to maintain and easier to read if someone else has to pick up after you. I have worked with Smarty before and it is nice, it keeps the designers work from interfering with the program code.

Using template systems and frameworks would make it much easier to accomplish tasks. There is a rule of thumb you can follow which is DRY (Don't Repeat Yourself). Frameworks help you achieve this goal.

You may want to look into MVC, this is the model that these frameworks are based off of. But you could implement this design structure without necessarily using framework. Avoiding the learning curve. For frameworks like Zend, the learning curve is much greater than some other ones.

I have found that Code Igniter is fairly easy to use and they have some VERY helpful video tutorials on their website.

Best of Luck!!

这篇关于PHP:分离业务逻辑和表达逻辑,值得吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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