在 Yii 的视图中,我应该更喜欢使用 widget 还是 renderPartial? [英] What should I prefer to use widget or renderPartial in Yii's view?

查看:26
本文介绍了在 Yii 的视图中,我应该更喜欢使用 widget 还是 renderPartial?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我应该在视图文件中使用自定义小部件或 renderPartial 时,我感到困惑.有时我使用小部件,有时我使用 renderPartial.

I am confused when I should use a custom widget or renderPartial in my view files. Sometimes I use widget and sometimes I use renderPartial.

推荐答案

Widget

当您的应用程序逻辑在单独的CLASS 文件中定义并且逻辑以某种方式分离和独立时,您可以使用widget.

You use widget when your application logic is defined in a separate CLASS file and the logic is somehow separated and standalone.

当该功能在很多页面上的其他地方重复使用时,会选择小部件.

Widget's are chosen when the functionality is repeatedly used elsewhere, on lot of pages.

renderPartial

您将 renderPartial 用于 VIEW 文件,以便将其嵌入到更大的文件中,或者当您想在不使用应用程序布局的情况下打印某些文件时.

You use renderPartial for VIEW files that you want to embed into something bigger, or when you want to print something without using the application layouts.

renderPartial 当它需要访问的所有变量已经在当前操作中准备好时被选择.

renderPartial is chosen when all the variables it need to access are already prepared in the current action.

这篇关于在 Yii 的视图中,我应该更喜欢使用 widget 还是 renderPartial?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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