Yii 什么时候用组件,什么时候用扩展? [英] When to use components and when to use extensions in Yii?

查看:42
本文介绍了Yii 什么时候用组件,什么时候用扩展?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 protected/中的组件和扩展文件夹的用途有点困惑

I'm a little bit confused about the purpose of components and extensions folders in protected/

请说明.

推荐答案

根据我在 Yii 上的一点经验:

According to my little experience on Yii:

组件是可以帮助您根据模型编写业务逻辑的类.您绝对不想在控制器中编写所有工作,那么您需要该组件来分发您的代码并在控制器中调用它.

Components are the classes which can help you write the business logic on the basis of your models. You definitely don't want to code all of your work in controllers, then you need the component to distribute your code and call it in controller.

扩展就像库,基本上不依赖于您的模型,因此可以在当前或以后的项目中的任何地方重用.例如:电子邮件扩展程序或向您的 Twitter 帐户发送推文的课程.

Extensions are like the libraries, which basically are not dependent on your models, and hence can be reused anywhere in current or later projects. For example: an email extension, or a class that send tweet to your twitter account.

其他编码员/用户可能会有所不同.

It may be different for other coders/users.

这篇关于Yii 什么时候用组件,什么时候用扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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