Yii – Dependency Injection
A DI(dependency injection) container is an object that knows how to instantiate and configure objects. Yii provides the DI container via the yii\di\Container class. It supports the following kinds of DI…
A DI(dependency injection) container is an object that knows how to instantiate and configure objects. Yii provides the DI container via the yii\di\Container class. It supports the following kinds of DI…
Configurations are used to create new objects or initializing the existing ones. Configurations usually include a class name and a list of initial values. They may also include a list…
Assume we want to create a behavior that will uppercase the βnameβ property of the component the behavior is attached to. Step 1 β Inside the components folder, create a file…
Behaviors are instances of the yii\base\Behavior class. A behavior injects its methods and properties to the component it is attached to. Behaviors can also respond to the events triggered by…
In this chapter we will see to create an event in Yii. To show events in action, we need data. Preparing the DB Step 1 β Create a new database. Database…
You can use events to inject custom code at certain execution points. You can attach custom code to an event, and when the event is triggered, the code gets executed. For example,…
The GridView widget takes data from a data provider and presents data in the form of a table. Each row of the table represents a single data item, and a…
The ListView widget uses a data provider to display data. Each model is rendered using the specified view file. Step 1 β Modify the actionDataWidget() method this way. public function actionDataWidget() { $dataProvider…
Yii provides a set of widgets for displaying data. You can use the DetailView widget to display a single record. The ListView widget, as well as Grid View, can be…
Yii provides a set of data provider classes that encapsulate pagination and sorting. A data provider implements yii\data\DataProviderInterface. It supports retrieving sorted and paginated data. Data providers usually work with…