Home> php教程> PHP开发> body text

yii2.0 widget production tutorial

黄舟
Release: 2017-01-03 09:27:56
Original
1191 people have browsed it

Widget production:

1. Take making a hello widget as an example. The following figure shows a simple directory structure (can be modified according to needs):

yii2.0 widget production tutorial

2. Open HelloWidget.php and add the following code:

render('index',['msg'=>$this->msg]); } }
Copy after login

3. Open the views layer rendering page common/hello/views/index.php

//简单举例,此处可以设计视图 
        
Copy after login

4. Small To call the widget, add the following code to the views layer page

'hello world'])?>
Copy after login

5. Display effect

yii2.0 widget production tutorial

The role of widgets is that there are many repetitions in the project Small functions, such as image upload and text editor, can be made into widgets to improve the code reuse rate. The effect is significant. I personally think that the entire website can be broken into many widgets.

The above is the content of the yii2.0 widget production tutorial. For more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!


Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!