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框架中库和助手的区别
				
        
 
            
        基础教程推荐
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
 - PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
 - 将变量从树枝传递给 js 2022-01-01
 - 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
 - Yii2 - 在运行时设置邮件传输参数 2022-01-01
 - Web 服务器如何处理请求? 2021-01-01
 - php中的foreach复选框POST 2021-01-01
 - php中的PDF导出 2022-01-01
 - 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
 - php 7.4 在写入变量中的 Twig 问题 2022-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
				
				
				
				