Home > Article > Backend Development > How to create simple widgets using yii2.0
This article mainly introduces the method of creating simple widgets in yii2.0, and analyzes the basic creation and use methods of widgets in Yii in the form of examples. Friends in need can refer to the following
The examples in this article describe Yii2.0 implements the method of creating simple widgets. Share it with everyone for your reference, the details are as follows:
namespace yii\widgets; use yii\base\Widget; use yii\helpers\Html; class HelloWidget extends Widget { public $message; public function init() { parent::init(); if ($this->message === null) { $this->message = 'Hello World'; } } public function run() { return Html::encode($this->message); } }
Calling method
<?php use app\components\HelloWidget; ?> <?= HelloWidget::widget(['message' => 'Good morning']) ?>
The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
How to deal with routing links in Yii2.0 Basic code Escape
yii2 component implements drop-down box with search function
##
The above is the detailed content of How to create simple widgets using yii2.0. For more information, please follow other related articles on the PHP Chinese website!