Development - Widgets
Generally widget is a class that inherits from CWidget helper class. It is a helper "component" that is mainly
used for presentational purposes. A widget is usually embedded in a view script to generate a complex,
yet self-contained user interface. For example, CFormView
widget can be used to render a
complex form user interface, CMenu
widget can be used to render a different
menus, CDataForm
allows work with models, save data, etc. Generaly widgets may be used in
controllers, views or in template files.
To use a widget, you have to call it in a following way:
<?php
echo CWidget::create('CMessage', array(
'info',
'Click <a href="login"><b>here</b></a> to log into the system as administrator.'
));
or
<?php
$output = CWidget::create('CMenu', array(
'type'=>'horizontal',
'class'=>'user_menu',
'items'=>array(
array('label'=>($viewRightMenu) ? 'Back to Admin Panel' : 'Home', 'url'=>'authors/index'),
array('label'=>'Logout', 'url'=>'login/logout'),
),
'return'=>true
));
Here the full list of current system widgets:
- CBreadCrumbs draws breadcrumbs
- CCaptcha draws captcha
- CCurrencySelector draws currency selector
- CDataForm created DataForm control
- CFormValidation performs validation of HTML forms
- CFormView draws HTML forms
- CGridView created GridView control
- CLanguageSelector draws language selector
- CMenu draws menu
- CMessage draws messages on the screen
- CPagination draws pagination control
- CTabs draws tabs control
Please note, that some widgets may be used by other widgets, so you may have an composite widget that
has many embedded simple widgets, like: CGridView, CFormView, etc. Also all keys in parameters are case-sensitive.
You may always check the CWidget class in core/helpers/CWidget.php
to learn the
syntax of each widget (included in the header comments of each widget file) or see the examples of
the code.