PHP框架中库和助手之间的区别 [英] difference between libraries and helpers in php frameworks

查看:112
本文介绍了PHP框架中库和助手之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有字符串函数,我使用了很多,我应该把它们放在助手类还是库类中?



函数如下:truncate string if longer超过30个字符,返回一个随机字符串,使所有小写字母等。这些是我可能不需要创建对象的函数。



我应该把它们放在一个库类还是一个辅助类中?


解决方案

帮手是帮助已经存在的东西的类,例如可以有一个帮助器:

数组

字符串

url



库可以是任何解决方案;它可能是你第一次创建,也没有其他人创建。

因为你正在处理一个字符串(已经存在的东西),你应该把它放在一个辅助类,或者修改框架的字符串帮助类(如果有的话)。然而,这是一个惯例或标准,但如果你正在创建一些非常酷的字符串处理功能,你可以为它创建一个库。


if i've got string functions i use a lot, should i put them in a helper class or a library class?

functions like: truncate string if longer than 30 characters, return a random string, make all lower cases and so on. these are functions that i probably don't need to create an object for. it's better to use them as static methods.

should i put them in a library class or a helper class?

when do i know when to put where?

解决方案

Helpers are the classes that help something already there for example there can be a helper for:

array
string
url
etc

A library is something that can be any solution; it could be created for the first time by you and no one else has created.

Because you are dealing with a string (something already there), you should put it in a helper class, or modify the string helper class of the framework (if there is one). However, this is a convention or standard but you can create a library for it too if you are creating something really cool for string handling with quite some functions.

这篇关于PHP框架中库和助手之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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