difference between libraries and helpers in php frameworks(php框架中库和助手的区别)
问题描述
如果我有我经常使用的字符串函数,我应该将它们放在帮助类还是库类中?
if i've got string functions i use a lot, should i put them in a helper class or a library class?
函数如:截断超过 30 个字符的字符串、返回随机字符串、全部小写等等.这些是我可能不需要为其创建对象的功能.最好将它们用作静态方法.
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?
推荐答案
Helper 是帮助已经存在的东西的类,例如可以有一个 helper:
Helpers are the classes that help something already there for example there can be a helper for:
数组
字符串
网址
等等
库可以是任何解决方案;它可能是您第一次创建的,没有其他人创建过.
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框架中库和助手的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:php框架中库和助手的区别
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- Laravel 仓库 2022-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01