Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering Yii

You're reading from   Mastering Yii Advance your modern web application development skills with Yii Framework 2

Arrow left icon
Product type Paperback
Published in Jan 2016
Publisher Packt
ISBN-13 9781785882425
Length 380 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Charles R. Portwood ll Charles R. Portwood ll
Author Profile Icon Charles R. Portwood ll
Charles R. Portwood ll
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface 1. Composer, Configuration, Classes, and Path Aliases FREE CHAPTER 2. Console Commands and Applications 3. Migrations, DAO, and Query Building 4. Active Record, Models, and Forms 5. Modules, Widgets, and Helpers 6. Asset Management 7. Authenticating and Authorizing Users 8. Routing, Responses, and Events 9. RESTful APIs 10. Testing with Codeception 11. Internationalization and Localization 12. Performance and Security 13. Debugging and Deploying Index

Widgets


In Yii2, widgets are reuseable code blocks that are used in views to add configurable user interface logic to our application in an object-oriented way. Yii2 comes with several different types of reusable widgets, some of which we have already seen in previous chapters. Custom widgets can also be created to create tools that can be reused across multiple projects. In this section, we'll go over the basic types of widgets, how to use them, and how to implement our own within our applications.

Using widgets

As a presentation layer tool, widgets are most commonly used within our view files. In Yii2, widgets can be used in one of two distinct ways. The first way to use widgets is to call the yii\base\Widget::widget() method on a supported widget within a view. This method takes a configuration array as an option and returns a rendered widget as a result. For instance, to display a Twitter Bootstrap 3 style alert on our page, we can use the yii\bootstrap\Alert widget as follows:

<?php...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image