Book Image

Mastering Yii

By : Charles R. Portwood ll
Book Image

Mastering Yii

By: Charles R. Portwood ll

Overview of this book

The successor of Yii Framework 1.1, Yii 2 is a complete rewrite of Yii Framework, one of the most popular PHP 5 frameworks around for making modern web applications. The update embraces the best practices and protocols established with newer versions of PHP, while still maintaining the simple, fast, and extendable behavior found in its predecessor. This book has been written to enhance your skills and knowledge with Yii Framework 2. Starting with configuration and how to initialize new projects, you’ll learn how to configure, manage, and use every aspect of Yii2 from Gii, DAO, Query Builder, Active Record, and migrations, to asset manager. You'll also discover how to automatically test your code using codeception. With this book by your side, you’ll have all the skills you need to quickly create rich modern web and console applications with Yii 2.
Table of Contents (20 chapters)
Mastering Yii
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
5
Modules, Widgets, and Helpers
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...