一般 MVC 问题 - 命名、结构 (PHP)
我尝试过很多 PHP MVC 框架,我注意到在很多框架中你可以做这样的事情:
$this->security->encodeForHTML();
所以,基本上有一个 Security 类,它包含一个方法encodeForHTML()。 这个Security类不是单例吗? 这种“内部”单例类有具体的名称吗?
因为还有其他类不是单例:
$form = new Form;
在这种情况下,您可以创建任意多个表单。 我理解这一点,初始化许多安全类显然没有意义,但我想知道这些类是否有名称(除了单例和非单例)? 一个人建议对那些可以创建的类使用“插件”一词,对那些在框架中构建的类使用“库”。 那有意义吗?
感谢您的回复!
I have tried many PHP MVC frameworks and I noticed that in many frameworks you can do things like this:
$this->security->encodeForHTML();
So, basically there is a class Security, which contains a method encodeForHTML(). Isn't this Security class a singleton? Is there a specific name for this kind of "internal" singleton class?
Because there are other classes that are not singletons:
$form = new Form;
In this case, you can create as many forms as you want. I understand the point of this, it clearly doesn't make sense to initialize many security classes, but I am wondering, are there names for these classes (other than singleton and non-singleton)? One guy suggested to use word "plugins" for those classes that can be created and "libraries" for those, which are built in the framework. Does that make sense?
Thanks for your reply!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当前的 MVC 时尚/命名约定调用这些帮助程序类/对象,它们与单例/非单例正交,(帮助程序通常创建为单例和/或具有静态方法的类,但不一定如此)
请参阅 Zend 示例文档。
插件这个描述不太正确。 通常,插件是由外部各方编写的代码/程序,用于利用和/或扩展系统内的功能。 如果您使用的系统为您提供了一种编写安全类并自动实例化它的方法,并且它的方法可供调用,并且您的安全类可以以标准的非黑客方式调用系统 API,则插件会更好方式。
Current MVC fashion/naming convention calls these Helper Classes/Objects, which is orthogonal to singleton/non-singleton, (helpers often are create as a singleton and/or class with static methods, but they don't have to be)
See Zend Documentation for an example.
A plugin isn't quite the right description. Typically plugins are code/programs written by outside parties to leverage and/or extend functionality within a system. A plugin would be more if the system you were using provided a way for YOU to write a security class and have it automatically instantiated and it's methods available to call, and if your security class could call on System APIs in a standard, non-hack way.
我同意你在帖子中提到的“一个人”。
IMO,这实际上取决于您使用哪种 MVC 框架。 我还没有尝试过其他框架,但在 CodeIgniter 中,这属于两件事:模型或库。 由于模型通常用于处理数据库中的信息,因此我将您提到的这个“安全”类称为库。
I agree with that 'one guy' you mentioned in your post.
IMO, it really depends on what kind of MVC framework you are using. I haven't tried other frameworks yet, but in CodeIgniter, this falls under two things, models or libraries. Since models are commonly used to handle informations from the database, I would call this 'security' class you mentioned, a library.