Data widgets

DetailView ListView GridView Further reading Yii provides a set of widgets that can be used to display data. While the DetailView widget can be used to display data for a single record, ListView and GridView can be used to display a list or table of data records providing features like pagination, sorting and filtering. DetailView The DetailView widget displays the details of a single data model. It is best used for displaying a model in a regular format (e.g. each model attribute is dis

Data Providers

Active Data Provider SQL Data Provider Array Data Provider Working with Data Keys Creating Custom Data Provider In the Pagination and Sorting sections, we have described how to allow end users to choose a particular page of data to display and sort them by some columns. Because the task of paginating and sorting data is very common, Yii provides a set of data provider classes to encapsulate it. A data provider is a class implementing yii\data\DataProviderInterface. It mainly supports retrievin

Data Formatting

Configuring Formatter Formatting Date and Time Values Formatting Numbers Other Formats Null Values Localizing Data Format To display data in a more readable format for users, you may format them using the formatter application component. By default the formatter is implemented by yii\i18n\Formatter which provides a set of methods to format data as date/time, numbers, currencies, and other commonly used formats. You can use the formatter like the following, $formatter = \Yii::$app->formatter

Data Caching

Cache Components Cache APIs Query Caching Data caching is about storing some PHP variables in cache and retrieving it later from cache. It is also the foundation for more advanced caching features, such as query caching and page caching. The following code is a typical usage pattern of data caching, where $cache refers to a cache component: // try retrieving $data from cache $data = $cache->get($key); if ($data === false) { // $data is not found in cache, calculate it from scratch

Creating your own Application structure

Clone the Basic Template Modify the Files Make a Package Use the Template Note: This section is under development. While the basic and advanced project templates are great for most of your needs, you may want to create your own project template with which to start your projects. Project templates in Yii are simply repositories containing a composer.json file, and registered as a Composer package. Any repository can be identified as a Composer package, making it installable via create-project

Core Validators

boolean captcha compare date default double each email exist file filter image ip in integer match number required safe string trim unique url Yii provides a set of commonly used core validators, found primarily under the yii\validators namespace. Instead of using lengthy validator class names, you may use aliases to specify the use of these core validators. For example, you can use the alias required to refer to the yii\validators\RequiredValidator class: public function rules() { return

Controllers

Actions Routes Creating Controllers Creating Actions Controller Lifecycle Best Practices Controllers are part of the MVC architecture. They are objects of classes extending from yii\base\Controller and are responsible for processing requests and generating responses. In particular, after taking over the control from applications, controllers will analyze incoming request data, pass them to models, inject model results into views, and finally generate outgoing responses. Actions Controllers a

Controllers

Creating Controller Classes Filters Extending ActiveController After creating the resource classes and specifying how resource data should be formatted, the next thing to do is to create controller actions to expose the resources to end users through RESTful APIs. Yii provides two base controller classes to simplify your work of creating RESTful actions: yii\rest\Controller and yii\rest\ActiveController. The difference between these two controllers is that the latter provides a default set of

console\Response

All Classes | Properties | Methods Inheritance yii\console\Response » yii\base\Response » yii\base\Component » yii\base\Object Implements yii\base\Configurable Available since version 2.0 Source Code https://github.com/yiisoft/yii2/blob/master/framework/console/Response.php The console Response represents the result of a console application. Public Properties Property Type Description Defined By $behaviors yii\base\Behavior[] List of behaviors attached to this component yii\base\Compon

console\Request setParams()

setParams() public method Sets the command line arguments. public void setParams ( $params )$params array The command line arguments