Home  >  Article  >  Backend Development  >  How to create simple widgets using yii2.0

How to create simple widgets using yii2.0

不言
不言Original
2018-06-15 15:50:351696browse

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([&#39;message&#39; => &#39;Good morning&#39;]) ?>

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:

Yii paging using CLinkPager

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn