I've noticed in my development with the Yii framework that there's
a function for many basic HTML elements (CHtml has button, link, etc.)
as well as for a menu (that could easily be replaced with a list).
My question is it considered ideal to use widgets wherever I can ?
When should I use HTML ?
相关问题
- Yii - Eliminate default controller ID for a module
- how to change csrf field id from YII_CSRF_TOKEN to
- Load balancing with Yii sessions
- Yii uploading pictures
- How to Auto Login and Redirect After Registration
相关文章
- Can you run console jobs from yii2-basic?
- How to do a bulk database insert in Yii2?
- Yii2 - check if the user is logged in view
- Call static method from a string name in PHP
- radioButtonList checked by default
- Postgres error: null value in column “id” - during
- Add column as link in CGridView
- yii : how to ajax update the cgridview
Widgets are neat wrappers to their HTML equivalents. Widgets in Yii typically also load the required JavaScript libraries. For example the CMaskedTextField in Yii contains a jQuery masked input plugin which it will load together with the widget. Coding the same HTML/JavaScript equivalent will require more lines of code.
One of the biggest advantages of using widgets is that you automate the
HTML
code generation, and this means more code/functionality with less coding.For example, in
Yii
you have theWidgetFactory
(in the config/main) where you can specify the default attributes for all your widgets. Changing the factory defaults changes your whole app/site widgets.This way, you only deal with some specific view where you may need to adapt your widget behavior.
You may also hack the
Widget
code to adapt theHTML
/js
code generation to fit your needs.Sometimes, frameworks replace basic HTML with their own widgets.
In the case of a link widget, the framework might do additional stuff like automatically giving it
class="active"
if the link is to the current page, so it can be styled differently.