The Definitive Guide to Yii 2.0

The Definitive Guide to Yii 2.0

The Definitive Guide to Yii 2.0

This tutorial is released under the Terms of Yii Documentation.

All Rights Reserved.

2014 (c) Yii Software LLC.



Data widgets in Yii 2
Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive

Data widgets

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.

Yii 2 Data Providers
Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive

Data Providers

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 retrieving paginated and sorted data. It is usually used to work with data widgets so that end users can interactively paginate and sort data.

The following data provider classes are included in the Yii releases:

  • [[yii\data\ActiveDataProvider]]: uses [[yii\db\Query]] or [[yii\db\ActiveQuery]] to query data from databases and return them in terms of arrays or Active Record instances.
  • [[yii\data\SqlDataProvider]]: executes a SQL statement and returns database data as arrays.
  • [[yii\data\ArrayDataProvider]]: takes a big array and returns a slice of it based on the paginating and sorting specifications.

The usage of all these data providers share the following common pattern:

// create the data provider by configuring its pagination and sort properties
$provider = new XyzDataProvider([
    'pagination' => [...],
    'sort' => [...],
]);

// retrieves paginated and sorted data
$models = $provider->getModels();

// get the number of data items in the current page
$count = $provider->getCount();

// get the total number of data items across all pages
$totalCount = $provider->getTotalCount();

You specify the pagination and sorting behaviors of a data provider by configuring its [[yii\data\BaseDataProvider::pagination|pagination]] and [[yii\data\BaseDataProvider::sort|sort]] properties which correspond to the configurations for [[yii\data\Pagination]] and [[yii\data\Sort]], respectively. You may also configure them to be false to disable pagination and/or sorting features.

Data widgets, such as [[yii\grid\GridView]], have a property named dataProvider which can take a data provider instance and display the data it provides. For example,

echo yii\grid\GridView::widget([
    'dataProvider' => $dataProvider,
]);

These data providers mainly vary in the way how the data source is specified. In the following subsections, we will explain the detailed usage of each of these data providers.

  • Active Data Provider
  • SQL Data Provider
  • Array Data Provider
  • Working with Data Keys
  • Creating Custom Data Provider
  • Filtering Data Providers using Data Filters

Active Data Provider

To use [[yii\data\ActiveDataProvider]], you should configure its [[yii\data\ActiveDataProvider::query|query]] property. It can take either a [[yii\db\Query]] or [[yii\db\ActiveQuery]] object. If the former, the data returned will be arrays; if the latter, the data returned can be either arrays or Active Record instances. For example,

use yii\data\ActiveDataProvider;

$query = Post::find()->where(['status' => 1]);

$provider = new ActiveDataProvider([
    'query' => $query,
    'pagination' => [
        'pageSize' => 10,
    ],
    'sort' => [
        'defaultOrder' => [
            'created_at' => SORT_DESC,
            'title' => SORT_ASC, 
        ]
    ],
]);

// returns an array of Post objects
$posts = $provider->getModels();

If $query in the above example is created using the following code, then the data provider will return raw arrays.

use yii\db\Query;

$query = (new Query())->from('post')->where(['status' => 1]);

Note: If a query already specifies the orderBy clause, the new ordering instructions given by end users (through the sort configuration) will be appended to the existing orderBy clause. Any existing limit and offset clauses will be overwritten by the pagination request from end users (through the pagination configuration).

By default, [[yii\data\ActiveDataProvider]] uses the db application component as the database connection. You may use a different database connection by configuring the [[yii\data\ActiveDataProvider::db]] property.

SQL Data Provider

[[yii\data\SqlDataProvider]] works with a raw SQL statement which is used to fetch the needed data. Based on the specifications of [[yii\data\SqlDataProvider::sort|sort]] and [[yii\data\SqlDataProvider::pagination|pagination]], the provider will adjust the ORDER BY and LIMIT clauses of the SQL statement accordingly to fetch only the requested page of data in the desired order.

To use [[yii\data\SqlDataProvider]], you should specify the [[yii\data\SqlDataProvider::sql|sql]] property as well as the [[yii\data\SqlDataProvider::totalCount|totalCount]] property. For example,

use yii\data\SqlDataProvider;

$count = Yii::$app->db->createCommand('
    SELECT COUNT(*) FROM post WHERE status=:status
', [':status' => 1])->queryScalar();

$provider = new SqlDataProvider([
    'sql' => 'SELECT * FROM post WHERE status=:status',
    'params' => [':status' => 1],
    'totalCount' => $count,
    'pagination' => [
        'pageSize' => 10,
    ],
    'sort' => [
        'attributes' => [
            'title',
            'view_count',
            'created_at',
        ],
    ],
]);

// returns an array of data rows
$models = $provider->getModels();

Info: The [[yii\data\SqlDataProvider::totalCount|totalCount]] property is required only if you need to paginate the data. This is because the SQL statement specified via [[yii\data\SqlDataProvider::sql|sql]] will be modified by the provider to return only the currently requested page of data. The provider still needs to know the total number of data items in order to correctly calculate the number of pages available.

Array Data Provider

[[yii\data\ArrayDataProvider]] is best used when working with a big array. The provider allows you to return a page of the array data sorted by one or multiple columns. To use [[yii\data\ArrayDataProvider]], you should specify the [[yii\data\ArrayDataProvider::allModels|allModels]] property as the big array. Elements in the big array can be either associative arrays (e.g. query results of DAO) or objects (e.g. Active Record instances). For example,

use yii\data\ArrayDataProvider;

$data = [
    ['id' => 1, 'name' => 'name 1', ...],
    ['id' => 2, 'name' => 'name 2', ...],
    ...
    ['id' => 100, 'name' => 'name 100', ...],
];

$provider = new ArrayDataProvider([
    'allModels' => $data,
    'pagination' => [
        'pageSize' => 10,
    ],
    'sort' => [
        'attributes' => ['id', 'name'],
    ],
]);

// get the rows in the currently requested page
$rows = $provider->getModels();

Note: Compared to Active Data Provider and SQL Data Provider, array data provider is less efficient because it requires loading all data into the memory.

Working with Data Keys

When using the data items returned by a data provider, you often need to identify each data item with a unique key. For example, if the data items represent customer information, you may want to use the customer ID as the key for each customer data. Data providers can return a list of such keys corresponding with the data items returned by [[yii\data\DataProviderInterface::getModels()]]. For example,

use yii\data\ActiveDataProvider;

$query = Post::find()->where(['status' => 1]);

$provider = new ActiveDataProvider([
    'query' => $query,
]);

// returns an array of Post objects
$posts = $provider->getModels();

// returns the primary key values corresponding to $posts
$ids = $provider->getKeys();

In the above example, because you provide to [[yii\data\ActiveDataProvider]] an [[yii\db\ActiveQuery]] object, it is intelligent enough to return primary key values as the keys. You may also explicitly specify how the key values should be calculated by configuring [[yii\data\ActiveDataProvider::key]] with a column name or a callable calculating key values. For example,

// use "slug" column as key values
$provider = new ActiveDataProvider([
    'query' => Post::find(),
    'key' => 'slug',
]);

// use the result of md5(id) as key values
$provider = new ActiveDataProvider([
    'query' => Post::find(),
    'key' => function ($model) {
        return md5($model->id);
    }
]);

Creating Custom Data Provider

To create your own custom data provider classes, you should implement [[yii\data\DataProviderInterface]]. An easier way is to extend from [[yii\data\BaseDataProvider]] which allows you to focus on the core data provider logic. In particular, you mainly need to implement the following methods:

  • [[yii\data\BaseDataProvider::prepareModels()|prepareModels()]]: prepares the data models that will be made available in the current page and returns them as an array.
  • [[yii\data\BaseDataProvider::prepareKeys()|prepareKeys()]]: accepts an array of currently available data models and returns keys associated with them.
  • [[yii\data\BaseDataProvider::prepareTotalCount()|prepareTotalCount]]: returns a value indicating the total number of data models in the data provider.

Below is an example of a data provider that reads CSV data efficiently:

<?php
use yii\data\BaseDataProvider;

class CsvDataProvider extends BaseDataProvider
{
    /**
     * @var string name of the CSV file to read
     */
    public $filename;
    
    /**
     * @var string|callable name of the key column or a callable returning it
     */
    public $key;
    
    /**
     * @var SplFileObject
     */
    protected $fileObject; // SplFileObject is very convenient for seeking to particular line in a file
    
 
    /**
     * {@inheritdoc}
     */
    public function init()
    {
        parent::init();
        
        // open file
        $this->fileObject = new SplFileObject($this->filename);
    }
 
    /**
     * {@inheritdoc}
     */
    protected function prepareModels()
    {
        $models = [];
        $pagination = $this->getPagination();
 
        if ($pagination === false) {
            // in case there's no pagination, read all lines
            while (!$this->fileObject->eof()) {
                $models[] = $this->fileObject->fgetcsv();
                $this->fileObject->next();
            }
        } else {
            // in case there's pagination, read only a single page
            $pagination->totalCount = $this->getTotalCount();
            $this->fileObject->seek($pagination->getOffset());
            $limit = $pagination->getLimit();
 
            for ($count = 0; $count < $limit; ++$count) {
                $models[] = $this->fileObject->fgetcsv();
                $this->fileObject->next();
            }
        }
 
        return $models;
    }
 
    /**
     * {@inheritdoc}
     */
    protected function prepareKeys($models)
    {
        if ($this->key !== null) {
            $keys = [];
 
            foreach ($models as $model) {
                if (is_string($this->key)) {
                    $keys[] = $model[$this->key];
                } else {
                    $keys[] = call_user_func($this->key, $model);
                }
            }
 
            return $keys;
        }

        return array_keys($models);
    }
 
    /**
     * {@inheritdoc}
     */
    protected function prepareTotalCount()
    {
        $count = 0;
 
        while (!$this->fileObject->eof()) {
            $this->fileObject->next();
            ++$count;
        }
 
        return $count;
    }
}

Filtering Data Providers using Data Filters

While you can build conditions for active data provider manually as described in Filtering Data and Separate Filter Form sections of data widgets guide, Yii has data filters that are very useful if you need flexible filter conditions. Data filters could be used as follows:

$filter = new ActiveDataFilter([
    'searchModel' => 'app\models\PostSearch'
]);

$filterCondition = null;

// You may load filters from any source. For example,
// if you prefer JSON in request body,
// use Yii::$app->request->getBodyParams() below:
if ($filter->load(\Yii::$app->request->get())) { 
    $filterCondition = $filter->build();
    if ($filterCondition === false) {
        // Serializer would get errors out of it
        return $filter;
    }
}

$query = Post::find();
if ($filterCondition !== null) {
    $query->andWhere($filterCondition);
}

return new ActiveDataProvider([
    'query' => $query,
]);

PostSearch model serves the purpose of defining which properties and values are allowed for filtering:

use yii\base\Model;

class PostSearch extends Model 
{
    public $id;
    public $title;
    
    public function rules()
    {
        return [
            ['id', 'integer'],
            ['title', 'string', 'min' => 2, 'max' => 200],            
        ];
    }
}

Data filters are quite flexible. You may customize how conditions are built and which operators are allowed. For details check API docs on [[\yii\data\DataFilter]].

Sorting in Yii 2
Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive

Sorting

When displaying multiple rows of data, it is often needed that the data be sorted according to some columns specified by end users. Yii uses a [[yii\data\Sort]] object to represent the information about a sorting schema. In particular,

  • [[yii\data\Sort::$attributes|attributes]] specifies the attributes by which the data can be sorted. An attribute can be as simple as a model attribute. It can also be a composite one by combining multiple model attributes or DB columns. More details will be given in the following.
  • [[yii\data\Sort::$attributeOrders|attributeOrders]] gives the currently requested ordering directions for each attribute.
  • [[yii\data\Sort::$orders|orders]] gives the ordering directions in terms of the low-level columns.

Pagination in Yii 2
Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive

Pagination

When there are too much data to be displayed on a single page, a common strategy is to display them in multiple pages and on each page only display a small portion of the data. This strategy is known as pagination.

Yii uses a [[yii\data\Pagination]] object to represent the information about a pagination scheme. In particular,

  • [[yii\data\Pagination::$totalCount|total count]] specifies the total number of data items. Note that this is usually much more than the number of data items needed to display on a single page.
  • [[yii\data\Pagination::$pageSize|page size]] specifies how many data items each page contains. The default value is 20.
  • [[yii\data\Pagination::$page|current page]] gives the current page number (zero-based). The default value is 0, meaning the first page.

Data Formatting in Yii 2
Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive

Data Formatting

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;

// output: January 1, 2014
echo $formatter->asDate('2014-01-01', 'long');
 
// output: 12.50%
echo $formatter->asPercent(0.125, 2);
 
// output: <a href="mailto:This email address is being protected from spambots. You need JavaScript enabled to view it.">This email address is being protected from spambots. You need JavaScript enabled to view it.</a>
echo $formatter->asEmail(This email address is being protected from spambots. You need JavaScript enabled to view it.'); 

// output: Yes
echo $formatter->asBoolean(true); 
// it also handles display of null values:

// output: (not set)
echo $formatter->asDate(null);

As you can see, all these methods are named as asXyz(), where Xyz stands for a supported format. Alternatively, you may format data using the generic method [[yii\i18n\Formatter::format()|format()]], which allows you to control the desired format programmatically and is commonly used by widgets like [[yii\grid\GridView]] and [[yii\widgets\DetailView]]. For example,

// output: January 1, 2014
echo Yii::$app->formatter->format('2014-01-01', 'date'); 

// you can also use an array to specify parameters for the format method:
// `2` is the value for the $decimals parameter of the asPercent()-method.
// output: 12.50%
echo Yii::$app->formatter->format(0.125, ['percent', 2]);

Note: The formatter component is designed to format values to be displayed for the end user. If you want to convert user input into machine readable format, or just format a date in a machine readable format, the formatter is not the right tool for that. To convert user input for date and number values you may use [[yii\validators\DateValidator]] and [[yii\validators\NumberValidator]] respectively. For simple conversion between machine readable date and time formats, the PHP date()-function is enough.

  • Configuring Formatter
  • Formatting Date and Time Values
    • Time Zones
  • Formatting Numbers
  • Other Formats
  • Null Values
  • Localizing Data Format

Configuring Formatter

You may customize the formatting rules by configuring the formatter component in the application configuration. For example,

return [
    'components' => [
        'formatter' => [
            'dateFormat' => 'dd.MM.yyyy',
            'decimalSeparator' => ',',
            'thousandSeparator' => ' ',
            'currencyCode' => 'EUR',
       ],
    ],
];

Please refer to [[yii\i18n\Formatter]] for the properties that may be configured.

Formatting Date and Time Values

The formatter supports the following output formats that are related with date and time:

  • [[yii\i18n\Formatter::asDate()|date]]: the value is formatted as a date, e.g. January 01, 2014.
  • [[yii\i18n\Formatter::asTime()|time]]: the value is formatted as a time, e.g. 14:23.
  • [[yii\i18n\Formatter::asDatetime()|datetime]]: the value is formatted as date and time, e.g. January 01, 2014 14:23.
  • [[yii\i18n\Formatter::asTimestamp()|timestamp]]: the value is formatted as a unix timestamp, e.g. 1412609982.
  • [[yii\i18n\Formatter::asRelativeTime()|relativeTime]]: the value is formatted as the time interval between a date and now in human readable form e.g. 1 hour ago.
  • [[yii\i18n\Formatter::asDuration()|duration]]: the value is formatted as a duration in human readable format. e.g. 1 day, 2 minutes.

The default date and time formats used for the [[yii\i18n\Formatter::asDate()|date]], [[yii\i18n\Formatter::asTime()|time]], and [[yii\i18n\Formatter::asDatetime()|datetime]] methods can be customized globally by configuring
[[yii\i18n\Formatter::dateFormat|dateFormat]], [[yii\i18n\Formatter::timeFormat|timeFormat]], and [[yii\i18n\Formatter::datetimeFormat|datetimeFormat]].

You can specify date and time formats using the ICU syntax. You can also use the PHP date() syntax with a prefix php: to differentiate it from ICU syntax. For example,

// ICU format
echo Yii::$app->formatter->asDate('now', 'yyyy-MM-dd'); // 2014-10-06

// PHP date()-format
echo Yii::$app->formatter->asDate('now', 'php:Y-m-d'); // 2014-10-06

Info: Some letters of the PHP format syntax are not supported by ICU and thus the PHP intl extension and can not be used in Yii formatter. Most of these (w, t, L, B, u, I, Z) are not really useful for formatting dates but rather used when doing date math. S and U however may be useful. Their behavior can be achieved by doing the following:

  • for S, which is the English ordinal suffix for the day of the month (e.g. st, nd, rd or th.), the following replacement can be used:

    код5
  • for U, the Unix Epoch, you can use the [[yii\i18n\Formatter::asTimestamp()|timestamp]] format.

When working with applications that need to support multiple languages, you often need to specify different date and time formats for different locales. To simplify this task, you may use format shortcuts (e.g. long, short), instead. The formatter will turn a format shortcut into an appropriate format according to the currently active [[yii\i18n\Formatter::locale|locale]]. The following format shortcuts are supported (the examples assume en_GB is the active locale):

  • short: will output 06/10/2014 for date and 15:58 for time;
  • medium: will output 6 Oct 2014 and 15:58:42;
  • long: will output 6 October 2014 and 15:58:42 GMT;
  • full: will output Monday, 6 October 2014 and 15:58:42 GMT.

Since version 2.0.7 it is also possible to format dates in different calendar systems. Please refer to the API documentation of the formatters [[yii\i18n\Formatter::$calendar|$calendar]]-property on how to set a different calendar.

Time Zones

When formatting date and time values, Yii will convert them to the target [[yii\i18n\Formatter::timeZone|time zone]]. The value being formatted is assumed to be in UTC, unless a time zone is explicitly given or you have configured [[yii\i18n\Formatter::defaultTimeZone]].

In the following examples, we assume the target [[yii\i18n\Formatter::timeZone|time zone]] is set as Europe/Berlin.

// formatting a UNIX timestamp as a time
echo Yii::$app->formatter->asTime(1412599260); // 14:41:00

// formatting a datetime string (in UTC) as a time 
echo Yii::$app->formatter->asTime('2014-10-06 12:41:00'); // 14:41:00

// formatting a datetime string (in CEST) as a time
echo Yii::$app->formatter->asTime('2014-10-06 14:41:00 CEST'); // 14:41:00

If the [[yii\i18n\Formatter::timeZone|time zone]] is not set explicitly on the formatter component, the [[yii\base\Application::timeZone|time zone configured in the application]] is used, which is the same time zone as set in the PHP configuration.

Note: As time zones are subject to rules made by the governments around the world and may change frequently, it is likely that you do not have the latest information in the time zone database installed on your system. You may refer to the ICU manual for details on updating the time zone database. Please also read Setting up your PHP environment for internationalization.

Formatting Numbers

The formatter supports the following output formats that are related with numbers:

  • [[yii\i18n\Formatter::asInteger()|integer]]: the value is formatted as an integer e.g. 42.
  • [[yii\i18n\Formatter::asDecimal()|decimal]]: the value is formatted as a decimal number considering decimal and thousand separators e.g. 2,542.123 or 2.542,123.
  • [[yii\i18n\Formatter::asPercent()|percent]]: the value is formatted as a percent number e.g. 42%.
  • [[yii\i18n\Formatter::asScientific()|scientific]]: the value is formatted as a number in scientific format e.g. 4.2E4.
  • [[yii\i18n\Formatter::asCurrency()|currency]]: the value is formatted as a currency value e.g. £420.00. Note that for this function to work properly, the locale needs to include a country part e.g. en_GB or en_US because language only would be ambiguous in this case.
  • [[yii\i18n\Formatter::asSize()|size]]: the value that is a number of bytes is formatted as a human readable size e.g. 410 kibibytes.
  • [[yii\i18n\Formatter::asShortSize()|shortSize]]: is the short version of [[yii\i18n\Formatter::asSize()|size]], e.g. 410 KiB.

The format for number formatting can be adjusted using the [[yii\i18n\Formatter::decimalSeparator|decimalSeparator]] and [[yii\i18n\Formatter::thousandSeparator|thousandSeparator]], both of which take default values according to the active [[yii\i18n\Formatter::locale|locale]].

For more advanced configuration, [[yii\i18n\Formatter::numberFormatterOptions]] and [[yii\i18n\Formatter::numberFormatterTextOptions]] can be used to configure the NumberFormatter class used internally to implement the formatter. For example, to adjust the maximum and minimum value of fraction digits, you can configure the [[yii\i18n\Formatter::numberFormatterOptions]] property like the following:

'numberFormatterOptions' => [
    NumberFormatter::MIN_FRACTION_DIGITS => 0,
    NumberFormatter::MAX_FRACTION_DIGITS => 2,
]

Other Formats

Besides date/time and number formats, Yii also supports other commonly used formats, including

  • [[yii\i18n\Formatter::asRaw()|raw]]: the value is outputted as is, this is a pseudo-formatter that has no effect except that null values will be formatted using [[nullDisplay]].
  • [[yii\i18n\Formatter::asText()|text]]: the value is HTML-encoded. This is the default format used by the GridView DataColumn.
  • [[yii\i18n\Formatter::asNtext()|ntext]]: the value is formatted as an HTML-encoded plain text with newlines converted into line breaks.
  • [[yii\i18n\Formatter::asParagraphs()|paragraphs]]: the value is formatted as HTML-encoded text paragraphs wrapped into <p> tags.
  • [[yii\i18n\Formatter::asHtml()|html]]: the value is purified using [[HtmlPurifier]] to avoid XSS attacks. You can pass additional options such as ['html', ['Attr.AllowedFrameTargets' => ['_blank']]].
  • [[yii\i18n\Formatter::asEmail()|email]]: the value is formatted as a mailto-link.
  • [[yii\i18n\Formatter::asImage()|image]]: the value is formatted as an image tag.
  • [[yii\i18n\Formatter::asUrl()|url]]: the value is formatted as a hyperlink.
  • [[yii\i18n\Formatter::asBoolean()|boolean]]: the value is formatted as a boolean. By default true is rendered as Yes and false as No, translated to the current application language. You can adjust this by configuring the [[yii\i18n\Formatter::booleanFormat]] property.

Null Values

Null values are specially formatted. Instead of displaying an empty string, the formatter will convert it into a preset string which defaults to (not set) translated into the current application language. You can configure the [[yii\i18n\Formatter::nullDisplay|nullDisplay]] property to customize this string.

Localizing Data Format

As aforementioned, the formatter may use the currently active [[yii\i18n\Formatter::locale|locale]] to determine how to format a value that is suitable in the target country/region. For example, the same date value may be formatted differently for different locales:

Yii::$app->formatter->locale = 'en-US';
echo Yii::$app->formatter->asDate('2014-01-01'); // output: January 1, 2014

Yii::$app->formatter->locale = 'de-DE';
echo Yii::$app->formatter->asDate('2014-01-01'); // output: 1. Januar 2014

Yii::$app->formatter->locale = 'ru-RU';
echo Yii::$app->formatter->asDate('2014-01-01'); // output: 1 января 2014 г.

By default, the currently active [[yii\i18n\Formatter::locale|locale]] is determined by the value of [[yii\base\Application::language]]. You may override it by setting the [[yii\i18n\Formatter::locale]] property explicitly.

Note: The Yii formatter relies on the PHP intl extension to support localized data formatting. Because different versions of the ICU library compiled with PHP may cause different formatting results, it is recommended that you use the same ICU version for all your environments. For more details, please refer to Setting up your PHP environment for internationalization.

If the intl extension is not installed, the data will not be localized.

Note that for date values that are before year 1901 or after 2038, they will not be localized on 32-bit systems, even if the intl extension is installed. This is because in this case ICU is using 32-bit UNIX timestamps to date values.

Extending yii2 ActiveForm on the Client Side
Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive

Extending ActiveForm on the Client Side

The [[yii\widgets\ActiveForm]] widget comes with a set of JavaScript methods that are used for client validation. Its implementation is very flexible and allows you to extend it in different ways. In the following these are described.

Subcategories