Class yii\base\Widget

Inheritanceyii\base\Widget » yii\base\Component » yii\base\Object
Implementsyii\base\Configurable, yii\base\ViewContextInterface
Subclassescommon\widgets\Alert, lispa\amos\admin\widgets\ConnectToUserWidget, lispa\amos\admin\widgets\GoogleContactWidget, lispa\amos\admin\widgets\UserCardWidget, lispa\amos\admin\widgets\UserContacsWidget, lispa\amos\admin\widgets\graphics\WidgetGraphicMyProfile, lispa\amos\admin\widgets\icons\WidgetIconAdmin, lispa\amos\admin\widgets\icons\WidgetIconCommunityManagerUserProfiles, lispa\amos\admin\widgets\icons\WidgetIconFacilitatorUserProfiles, lispa\amos\admin\widgets\icons\WidgetIconInactiveUserProfiles, lispa\amos\admin\widgets\icons\WidgetIconMyProfile, lispa\amos\admin\widgets\icons\WidgetIconUserProfile, lispa\amos\admin\widgets\icons\WidgetIconValidatedUserProfiles, lispa\amos\attachments\components\AttachmentsList, lispa\amos\attachments\components\AttachmentsTable, lispa\amos\attachments\components\AttachmentsTableWithPreview, lispa\amos\attachments\components\CropInput, lispa\amos\chat\widgets\ConversationWidget, lispa\amos\chat\widgets\MessageWidget, lispa\amos\chat\widgets\UserContactsWidget, lispa\amos\chat\widgets\icons\WidgetIconChat, lispa\amos\chat\widgets\icons\WidgetIconChatAssistance, lispa\amos\comments\widgets\CommentsWidget, lispa\amos\community\widgets\CommunityCardWidget, lispa\amos\community\widgets\CommunityMembersWidget, lispa\amos\community\widgets\CommunityPublishedContentsWidget, lispa\amos\community\widgets\JoinCommunityWidget, lispa\amos\community\widgets\SubcommunitiesWidget, lispa\amos\community\widgets\UserNetworkWidget, lispa\amos\community\widgets\graphics\WidgetGraphicsCommunityReports, lispa\amos\community\widgets\graphics\WidgetGraphicsMyCommunities, lispa\amos\community\widgets\graphics\WidgetHackathonCampusParty, lispa\amos\community\widgets\icons\WidgetIconAccademyDocument, lispa\amos\community\widgets\icons\WidgetIconAdminAllCommunity, lispa\amos\community\widgets\icons\WidgetIconCommunity, lispa\amos\community\widgets\icons\WidgetIconCommunityDashboard, lispa\amos\community\widgets\icons\WidgetIconCreatedByCommunities, lispa\amos\community\widgets\icons\WidgetIconMyCommunities, lispa\amos\community\widgets\icons\WidgetIconToValidateCommunities, lispa\amos\community\widgets\mini\CommunityMembersMiniWidget, lispa\amos\community\widgets\mini\SubcommunitiesMiniWidget, lispa\amos\comuni\widgets\helpers\AmosComuniWidget, lispa\amos\comuni\widgets\icons\WidgetIconAmmComuni, lispa\amos\comuni\widgets\icons\WidgetIconComuni, lispa\amos\comuni\widgets\icons\WidgetIconImportatoreCap, lispa\amos\comuni\widgets\icons\WidgetIconImportatoreCodiciCatastali, lispa\amos\comuni\widgets\icons\WidgetIconImportatoreComuni, lispa\amos\comuni\widgets\icons\WidgetIconProvince, lispa\amos\comuni\widgets\icons\WidgetIconVariazioniComuni, lispa\amos\core\forms\AccordionWidget, lispa\amos\core\forms\ActiveForm, lispa\amos\core\forms\AmosCarouselWidget, lispa\amos\core\forms\AmosOwlCarouselWidget, lispa\amos\core\forms\AttachmentsWidget, lispa\amos\core\forms\CloseButtonWidget, lispa\amos\core\forms\CloseSaveButtonWidget, lispa\amos\core\forms\ContentSettingsMenuWidget, lispa\amos\core\forms\ContextMenuWidget, lispa\amos\core\forms\CreateNewButtonWidget, lispa\amos\core\forms\CreatedUpdatedWidget, lispa\amos\core\forms\InformationRequestWidget, lispa\amos\core\forms\InteractionMenuWidget, lispa\amos\core\forms\ItemAndCardHeaderWidget, lispa\amos\core\forms\ListTagsWidget, lispa\amos\core\forms\MapWidget, lispa\amos\core\forms\PublishedByWidget, lispa\amos\core\forms\PublishedContentsWidget, lispa\amos\core\forms\RecaptchaV3Widget, lispa\amos\core\forms\RequiredFieldsTipWidget, lispa\amos\core\forms\ShowUserAreeInteresseWidget, lispa\amos\core\forms\ShowUserTagsWidget, lispa\amos\core\forms\Tabs, lispa\amos\core\forms\WidgetGraphicsActions, lispa\amos\core\forms\WizardPrevAndContinueButtonWidget, lispa\amos\core\forms\editors\AmministratoriCondominioWidget, lispa\amos\core\forms\editors\CarteWidget, lispa\amos\core\forms\editors\CondominiAmmWidget, lispa\amos\core\forms\editors\CondominiWidget, lispa\amos\core\forms\editors\ContattiWidget, lispa\amos\core\forms\editors\UtentiCondominioWidget, lispa\amos\core\forms\editors\m2mWidget\M2MWidget, lispa\amos\core\toolbar\Nav, lispa\amos\core\toolbar\NavBar, lispa\amos\core\toolbar\NavBarOverriden, lispa\amos\core\views\AmosGridView, lispa\amos\core\views\AmosLinkPager, lispa\amos\core\views\CalendarView, lispa\amos\core\views\ChangeView, lispa\amos\core\views\DataProviderView, lispa\amos\core\views\GanttView, lispa\amos\core\views\IconView, lispa\amos\core\views\ListView, lispa\amos\core\views\MapView, lispa\amos\core\views\common\BaseListView, lispa\amos\core\views\toolbars\StatsToolbar, lispa\amos\core\widget\WidgetAbstract, lispa\amos\core\widget\WidgetGraphic, lispa\amos\core\widget\WidgetIcon, lispa\amos\cwh\widgets\Cwh3ColsWidget, lispa\amos\cwh\widgets\CwhWidget, lispa\amos\cwh\widgets\Destinatari, lispa\amos\cwh\widgets\DestinatariNEW, lispa\amos\cwh\widgets\DestinatariPlusTagWidget, lispa\amos\cwh\widgets\RecipientsCheck, lispa\amos\cwh\widgets\RecipientsCheckNEW, lispa\amos\cwh\widgets\RegolaPubblicazione, lispa\amos\cwh\widgets\RegolaPubblicazioneNEW, lispa\amos\cwh\widgets\TagWidgetAreeInteresse, lispa\amos\cwh\widgets\UserNetworkWidget, lispa\amos\cwh\widgets\Validatori, lispa\amos\cwh\widgets\ValidatoriNEW, lispa\amos\cwh\widgets\icons\WidgetIconCwhAuthAssignment, lispa\amos\cwh\widgets\icons\WidgetIconCwhConfig, lispa\amos\cwh\widgets\icons\WidgetIconCwhNodi, lispa\amos\cwh\widgets\icons\WidgetIconCwhRegolePubblicazione, lispa\amos\dashboard\widgets\DashboardWidget, lispa\amos\dashboard\widgets\SubDashboardWidget, lispa\amos\discussioni\widgets\DiscussionsCarouselWidget, lispa\amos\discussioni\widgets\graphics\WidgetGraphicsDiscussioniInEvidenza, lispa\amos\discussioni\widgets\graphics\WidgetGraphicsUltimeDiscussioni, lispa\amos\discussioni\widgets\icons\WidgetIconDiscussioni, lispa\amos\discussioni\widgets\icons\WidgetIconDiscussioniDashboard, lispa\amos\discussioni\widgets\icons\WidgetIconDiscussioniTopic, lispa\amos\discussioni\widgets\icons\WidgetIconDiscussioniTopicAdminAll, lispa\amos\discussioni\widgets\icons\WidgetIconDiscussioniTopicAll, lispa\amos\discussioni\widgets\icons\WidgetIconDiscussioniTopicCreatedBy, lispa\amos\discussioni\widgets\icons\WidgetIconDiscussioniTopicDaValidare, lispa\amos\documenti\widgets\DocumentsOwlCarouselWidget, lispa\amos\documenti\widgets\graphics\WidgetGraphicsHierarchicalDocuments, lispa\amos\documenti\widgets\graphics\WidgetGraphicsUltimiDocumenti, lispa\amos\documenti\widgets\icons\WidgetIconAdminAllDocumenti, lispa\amos\documenti\widgets\icons\WidgetIconAllDocumenti, lispa\amos\documenti\widgets\icons\WidgetIconDocumenti, lispa\amos\documenti\widgets\icons\WidgetIconDocumentiCategorie, lispa\amos\documenti\widgets\icons\WidgetIconDocumentiCreatedBy, lispa\amos\documenti\widgets\icons\WidgetIconDocumentiDaValidare, lispa\amos\documenti\widgets\icons\WidgetIconDocumentiDashboard, lispa\amos\een\widgets\icons\WidgetIconEen, lispa\amos\een\widgets\icons\WidgetIconEenAll, lispa\amos\een\widgets\icons\WidgetIconEenArchived, lispa\amos\een\widgets\icons\WidgetIconEenDashboard, lispa\amos\een\widgets\icons\WidgetIconEenExprOfInterest, lispa\amos\een\widgets\icons\WidgetIconEenExprOfInterestAll, lispa\amos\een\widgets\icons\WidgetIconEenExprOfInterestDashboard, lispa\amos\een\widgets\icons\WidgetIconEenExprOfInterestReceived, lispa\amos\een\widgets\icons\WidgetIconEenStaff, lispa\amos\emailmanager\widgets\icons\WidgetIconEmailManager, lispa\amos\emailmanager\widgets\icons\WidgetIconSpool, lispa\amos\emailmanager\widgets\icons\WidgetIconTemplate, lispa\amos\events\widgets\EventsPublishedByWidget, lispa\amos\events\widgets\EventsShowUserTagsWidget, lispa\amos\events\widgets\icons\WidgetIconEventOwnInterest, lispa\amos\events\widgets\icons\WidgetIconEventTypes, lispa\amos\events\widgets\icons\WidgetIconEvents, lispa\amos\events\widgets\icons\WidgetIconEventsCreatedBy, lispa\amos\events\widgets\icons\WidgetIconEventsManagement, lispa\amos\events\widgets\icons\WidgetIconEventsToPublish, lispa\amos\faq\widgets\icons\WidgetIconFaq, lispa\amos\faq\widgets\icons\WidgetIconFaqCategorie, lispa\amos\faq\widgets\icons\WidgetIconFaqDashboard, lispa\amos\faq\widgets\icons\WidgetIconFaqStati, lispa\amos\favorites\widgets\FavoriteWidget, lispa\amos\inforeq\widgets\icons\WidgetIconInforeq, lispa\amos\inforeq\widgets\icons\WidgetIconInforeqAdmin, lispa\amos\invitations\widgets\InviteUserWidget, lispa\amos\invitations\widgets\icons\WidgetIconInvitations, lispa\amos\invitations\widgets\icons\WidgetIconInvitationsAll, lispa\amos\layout\toolbar\Nav, lispa\amos\layout\toolbar\NavBar, lispa\amos\layout\toolbar\NavBarOverriden, lispa\amos\myactivities\widgets\UserRequestValidation, lispa\amos\myactivities\widgets\icons\WidgetIconMyActivities, lispa\amos\news\widgets\NewsCarouselWidget, lispa\amos\news\widgets\graphics\WidgetGraphicsUltimeNews, lispa\amos\news\widgets\icons\WidgetIconAdminAllNews, lispa\amos\news\widgets\icons\WidgetIconAllNews, lispa\amos\news\widgets\icons\WidgetIconNews, lispa\amos\news\widgets\icons\WidgetIconNewsCategorie, lispa\amos\news\widgets\icons\WidgetIconNewsCreatedBy, lispa\amos\news\widgets\icons\WidgetIconNewsDaValidare, lispa\amos\news\widgets\icons\WidgetIconNewsDashboard, lispa\amos\notificationmanager\forms\NewsWidget, lispa\amos\notificationmanager\views\widgets\NotificationNavDecorator, lispa\amos\notificationmanager\widgets\NotifyFrequencyWidget, lispa\amos\organizzazioni\widgets\JoinProfiloWidget, lispa\amos\organizzazioni\widgets\JoinedOrgParticipantsTasksWidget, lispa\amos\organizzazioni\widgets\JoinedOrganizationsWidget, lispa\amos\organizzazioni\widgets\ProfiloCardWidget, lispa\amos\organizzazioni\widgets\UserNetworkWidget, lispa\amos\organizzazioni\widgets\icons\WidgetIconProfilo, lispa\amos\organizzazioni\widgets\maps\PlaceWidget, lispa\amos\partnershipprofiles\widgets\ExpressYourInterestWidget, lispa\amos\partnershipprofiles\widgets\graphics\WidgetGraphicsLatestPartnershipProfiles, lispa\amos\partnershipprofiles\widgets\icons\WidgetIconExpressionsOfInterestAllAdmin, lispa\amos\partnershipprofiles\widgets\icons\WidgetIconExpressionsOfInterestCreatedBy, lispa\amos\partnershipprofiles\widgets\icons\WidgetIconExpressionsOfInterestDashboard, lispa\amos\partnershipprofiles\widgets\icons\WidgetIconExpressionsOfInterestReceived, lispa\amos\partnershipprofiles\widgets\icons\WidgetIconPartnerProfExprOfIntDashboard, lispa\amos\partnershipprofiles\widgets\icons\WidgetIconPartnerProfExprOfIntExprOfInt, lispa\amos\partnershipprofiles\widgets\icons\WidgetIconPartnerProfExprOfIntPartProf, lispa\amos\partnershipprofiles\widgets\icons\WidgetIconPartnershipProfilesAll, lispa\amos\partnershipprofiles\widgets\icons\WidgetIconPartnershipProfilesAllAdmin, lispa\amos\partnershipprofiles\widgets\icons\WidgetIconPartnershipProfilesArchived, lispa\amos\partnershipprofiles\widgets\icons\WidgetIconPartnershipProfilesClosed, lispa\amos\partnershipprofiles\widgets\icons\WidgetIconPartnershipProfilesCreatedBy, lispa\amos\partnershipprofiles\widgets\icons\WidgetIconPartnershipProfilesDashboard, lispa\amos\partnershipprofiles\widgets\icons\WidgetIconPartnershipProfilesOwnInterest, lispa\amos\partnershipprofiles\widgets\icons\WidgetIconPartnershipProfilesToValidate, lispa\amos\privileges\widgets\UserPrivilegesWidget, lispa\amos\projectmanagement\widgets\ActivitiesTasksWidget, lispa\amos\projectmanagement\widgets\DependenciesTasksWidget, lispa\amos\projectmanagement\widgets\ParticipantsTasksWidget, lispa\amos\projectmanagement\widgets\ProjectOrganizationsWidget, lispa\amos\projectmanagement\widgets\ProjectSpendingVoicesWidget, lispa\amos\projectmanagement\widgets\icons\WidgetIconCreatedByProjects, lispa\amos\projectmanagement\widgets\icons\WidgetIconMyProjects, lispa\amos\projectmanagement\widgets\icons\WidgetIconOwnProjects, lispa\amos\projectmanagement\widgets\icons\WidgetIconProjectManagement, lispa\amos\projectmanagement\widgets\icons\WidgetIconProjectsActivities, lispa\amos\projectmanagement\widgets\icons\WidgetIconprojects, lispa\amos\report\widgets\ReportDropdownWidget, lispa\amos\report\widgets\ReportFlagWidget, lispa\amos\report\widgets\ReportWidget, lispa\amos\report\widgets\ReportsListModalWidget, lispa\amos\report\widgets\TabReportsWidget, lispa\amos\risultati\widgets\icons\WidgetIconBisognoPerSviluppoRisultati, lispa\amos\risultati\widgets\icons\WidgetIconProtezioneInnovazioneRisultati, lispa\amos\risultati\widgets\icons\WidgetIconRisultati, lispa\amos\risultati\widgets\icons\WidgetIconRisultatiDashboard, lispa\amos\risultati\widgets\icons\WidgetIconStadioSviluppoRisultati, lispa\amos\risultati\widgets\icons\WidgetIconTecnologieRisultati, lispa\amos\seo\widgets\MetaWidget, lispa\amos\seo\widgets\RobotWidget, lispa\amos\seo\widgets\SeoWidget, lispa\amos\seo\widgets\SocialWidget, lispa\amos\slideshow\widgets\SlideshowWidget, lispa\amos\slideshow\widgets\icons\WidgetIconSlideshow, lispa\amos\slideshow\widgets\icons\WidgetIconSlideshowConf, lispa\amos\socialauth\components\SocialAuthBar, lispa\amos\socialauth\components\SocialLinkBar, lispa\amos\socialauth\components\SocialLinkTable, lispa\amos\socialauth\components\SocialSignUpBar, lispa\amos\sondaggi\components\GraficiGoogle, lispa\amos\sondaggi\widgets\icons\WidgetIconAmministraSondaggi, lispa\amos\sondaggi\widgets\icons\WidgetIconCompilaSondaggi, lispa\amos\sondaggi\widgets\icons\WidgetIconPubblicaSondaggi, lispa\amos\sondaggi\widgets\icons\WidgetIconSondaggi, lispa\amos\sondaggi\widgets\icons\WidgetIconSondaggiAdministration, lispa\amos\tag\widgets\ShowTagsWidget, lispa\amos\tag\widgets\TagWidget, lispa\amos\tag\widgets\icons\WidgetIconTag, lispa\amos\tag\widgets\icons\WidgetIconTagManager, lispa\amos\translation\widgets\icons\WidgetIconTrContents, lispa\amos\translation\widgets\icons\WidgetIconTrLanguage, lispa\amos\translation\widgets\icons\WidgetIconTrOptimize, lispa\amos\translation\widgets\icons\WidgetIconTrPlatform, lispa\amos\translation\widgets\icons\WidgetIconTrScan, lispa\amos\translation\widgets\icons\WidgetIconTrTranslators, lispa\amos\translation\widgets\icons\WidgetIconTranslation, lispa\amos\upload\widgets\UploadWidget, lispa\amos\videoconference\widgets\icons\WidgetIconVideoconference, lispa\amos\wizflow\widgets\WizflowPrevAndContinueButtonWidget, pendalf89\filemanager\widgets\FileInput, pendalf89\filemanager\widgets\TinyMce, pendalf89\tinymce\TinyMce, yii\bootstrap\ActiveForm, yii\bootstrap\Alert, yii\bootstrap\Button, yii\bootstrap\ButtonDropdown, yii\bootstrap\ButtonGroup, yii\bootstrap\Carousel, yii\bootstrap\Collapse, yii\bootstrap\Dropdown, yii\bootstrap\InputWidget, yii\bootstrap\Modal, yii\bootstrap\Nav, yii\bootstrap\NavBar, yii\bootstrap\Progress, yii\bootstrap\Tabs, yii\bootstrap\ToggleButtonGroup, yii\bootstrap\Widget, yii\captcha\Captcha, yii\grid\GridView, yii\jui\Accordion, yii\jui\AutoComplete, yii\jui\DatePicker, yii\jui\Dialog, yii\jui\Draggable, yii\jui\Droppable, yii\jui\InputWidget, yii\jui\Menu, yii\jui\ProgressBar, yii\jui\Resizable, yii\jui\Selectable, yii\jui\Slider, yii\jui\SliderInput, yii\jui\Sortable, yii\jui\Spinner, yii\jui\Tabs, yii\jui\Widget, yii\widgets\ActiveForm, yii\widgets\BaseListView, yii\widgets\Block, yii\widgets\Breadcrumbs, yii\widgets\ContentDecorator, yii\widgets\DetailView, yii\widgets\FragmentCache, yii\widgets\InputWidget, yii\widgets\LinkPager, yii\widgets\LinkSorter, yii\widgets\ListView, yii\widgets\MaskedInput, yii\widgets\Menu, yii\widgets\Pjax, yii\widgets\Spaceless
Available since version2.0
Source Code https://github.com/yiisoft/yii2/blob/master/framework/base/Widget.php

Widget is the base class for widgets.

For more details and usage information on Widget, see the guide article on widgets.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$autoIdPrefix string The prefix to the automatically generated widget IDs. yii\base\Widget
$behaviors yii\base\Behavior[] List of behaviors attached to this component yii\base\Component
$counter integer A counter used to generate $id for widgets. yii\base\Widget
$id string ID of the widget. yii\base\Widget
$stack yii\base\Widget[] The widgets that are currently being rendered (not ended). yii\base\Widget
$view yii\web\View The view object that can be used to render views or view files. yii\base\Widget
$viewPath string The directory containing the view files for this widget. yii\base\Widget

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__call() Calls the named method which is not a class method. yii\base\Component
__clone() This method is called after the object is created by cloning an existing one. yii\base\Component
__construct() Constructor. yii\base\Object
__get() Returns the value of a component property. yii\base\Component
__isset() Checks if a property is set, i.e. defined and not null. yii\base\Component
__set() Sets the value of a component property. yii\base\Component
__unset() Sets a component property to be null. yii\base\Component
afterRun() This method is invoked right after a widget is executed. yii\base\Widget
attachBehavior() Attaches a behavior to this component. yii\base\Component
attachBehaviors() Attaches a list of behaviors to the component. yii\base\Component
beforeRun() This method is invoked right before the widget is executed. yii\base\Widget
begin() Begins a widget. yii\base\Widget
behaviors() Returns a list of behaviors that this component should behave as. yii\base\Component
canGetProperty() Returns a value indicating whether a property can be read. yii\base\Component
canSetProperty() Returns a value indicating whether a property can be set. yii\base\Component
className() Returns the fully qualified name of this class. yii\base\Object
detachBehavior() Detaches a behavior from the component. yii\base\Component
detachBehaviors() Detaches all behaviors from the component. yii\base\Component
end() Ends a widget. yii\base\Widget
ensureBehaviors() Makes sure that the behaviors declared in behaviors() are attached to this component. yii\base\Component
getBehavior() Returns the named behavior object. yii\base\Component
getBehaviors() Returns all behaviors attached to this component. yii\base\Component
getId() Returns the ID of the widget. yii\base\Widget
getView() Returns the view object that can be used to render views or view files. yii\base\Widget
getViewPath() Returns the directory containing the view files for this widget. yii\base\Widget
hasEventHandlers() Returns a value indicating whether there is any handler attached to the named event. yii\base\Component
hasMethod() Returns a value indicating whether a method is defined. yii\base\Component
hasProperty() Returns a value indicating whether a property is defined for this component. yii\base\Component
init() Initializes the object. yii\base\Widget
off() Detaches an existing event handler from this component. yii\base\Component
on() Attaches an event handler to an event. yii\base\Component
render() Renders a view. yii\base\Widget
renderFile() Renders a view file. yii\base\Widget
run() Executes the widget. yii\base\Widget
setId() Sets the ID of the widget. yii\base\Widget
setView() Sets the view object to be used by this widget. yii\base\Widget
trigger() Triggers an event. yii\base\Component
widget() Creates a widget instance and runs it. yii\base\Widget

Events

Hide inherited events

EventTypeDescriptionDefined By
EVENT_AFTER_RUN yii\base\WidgetEvent An event raised right after executing a widget. (available since version 2.0.11) yii\base\Widget
EVENT_BEFORE_RUN yii\base\WidgetEvent An event raised right before executing a widget. (available since version 2.0.11) yii\base\Widget
EVENT_INIT yii\base\Event An event that is triggered when the widget is initialized via init(). (available since version 2.0.11) yii\base\Widget

Property Details

$autoIdPrefix public static property

The prefix to the automatically generated widget IDs.

See also getId().

public static string $autoIdPrefix 'w'
$counter public static property

A counter used to generate $id for widgets.

public static integer $counter 0
$id public property

ID of the widget.

public string getId ( $autoGenerate true )
public void setId ( $value )
$stack public static property

The widgets that are currently being rendered (not ended). This property is maintained by begin() and end() methods.

public static yii\base\Widget[] $stack = []
$view public property

The view object that can be used to render views or view files.

public yii\web\View getView ( )
public void setView ( $view )
$viewPath public read-only property

The directory containing the view files for this widget.

public string getViewPath ( )

Method Details

afterRun() public method (available since version 2.0.11)

This method is invoked right after a widget is executed.

The method will trigger the EVENT_AFTER_RUN event. The return value of the method will be used as the widget return value.

If you override this method, your code should look like the following:

public function afterRun($result)
{
    $result = parent::afterRun($result);
    // your custom code here
    return $result;
}
public mixed afterRun ( $result )
$result mixed

The widget return result.

return mixed

The processed widget result.

beforeRun() public method (available since version 2.0.11)

This method is invoked right before the widget is executed.

The method will trigger the EVENT_BEFORE_RUN event. The return value of the method will determine whether the widget should continue to run.

When overriding this method, make sure you call the parent implementation like the following:

public function beforeRun()
{
    if (!parent::beforeRun()) {
        return false;
    }

    // your custom code here

    return true; // or false to not run the widget
}
public boolean beforeRun ( )
return boolean

Whether the widget should continue to be executed.

begin() public static method

Begins a widget.

This method creates an instance of the calling class. It will apply the configuration to the created instance. A matching end() call should be called later. As some widgets may use output buffering, the end() call should be made in the same view to avoid breaking the nesting of output buffers.

See also end().

public static static begin ( $config = [] )
$config array

Name-value pairs that will be used to initialize the object properties

return static

The newly created widget instance

end() public static method

Ends a widget.

Note that the rendering result of the widget is directly echoed out.

See also begin().

public static static end ( )
return static

The widget instance that is ended.

throws yii\base\InvalidCallException

if begin() and end() calls are not properly nested

getId() public method

Returns the ID of the widget.

public string getId ( $autoGenerate true )
$autoGenerate boolean

Whether to generate an ID if it is not set previously

return string

ID of the widget.

getView() public method

Returns the view object that can be used to render views or view files.

The render() and renderFile() methods will use this view object to implement the actual view rendering. If not set, it will default to the "view" application component.

public yii\web\View getView ( )
return yii\web\View

The view object that can be used to render views or view files.

getViewPath() public method

Returns the directory containing the view files for this widget.

The default implementation returns the 'views' subdirectory under the directory containing the widget class file.

public string getViewPath ( )
return string

The directory containing the view files for this widget.

init() public method

Initializes the object.

This method is called at the end of the constructor. The default implementation will trigger an EVENT_INIT event.

public void init ( )
render() public method

Renders a view.

The view to be rendered can be specified in one of the following formats:

  • path alias (e.g. "@app/views/site/index");
  • absolute path within application (e.g. "//site/index"): the view name starts with double slashes. The actual view file will be looked for under the view path of the application.
  • absolute path within module (e.g. "/site/index"): the view name starts with a single slash. The actual view file will be looked for under the view path of the currently active module.
  • relative path (e.g. "index"): the actual view file will be looked for under $viewPath.

If the view name does not contain a file extension, it will use the default one .php.

public string render ( $view, $params = [] )
$view string

The view name.

$params array

The parameters (name-value pairs) that should be made available in the view.

return string

The rendering result.

throws yii\base\InvalidParamException

if the view file does not exist.

renderFile() public method

Renders a view file.

public string renderFile ( $file, $params = [] )
$file string

The view file to be rendered. This can be either a file path or a path alias.

$params array

The parameters (name-value pairs) that should be made available in the view.

return string

The rendering result.

throws yii\base\InvalidParamException

if the view file does not exist.

run() public method

Executes the widget.

public string run ( )
return string

The result of widget execution to be outputted.

setId() public method

Sets the ID of the widget.

public void setId ( $value )
$value string

Id of the widget.

setView() public method

Sets the view object to be used by this widget.

public void setView ( $view )
$view yii\base\View

The view object that can be used to render views or view files.

widget() public static method

Creates a widget instance and runs it.

The widget rendering result is returned by this method.

public static string widget ( $config = [] )
$config array

Name-value pairs that will be used to initialize the object properties

return string

The rendering result of the widget.

throws Exception

Event Details

EVENT_AFTER_RUN event of type yii\base\WidgetEvent (available since version 2.0.11)

An event raised right after executing a widget.

EVENT_BEFORE_RUN event of type yii\base\WidgetEvent (available since version 2.0.11)

An event raised right before executing a widget. You may set yii\base\WidgetEvent::$isValid to be false to cancel the widget execution.

EVENT_INIT event of type yii\base\Event (available since version 2.0.11)

An event that is triggered when the widget is initialized via init().