data\ActiveDataProvider prepareTotalCount()

prepareTotalCount() protected method Returns a value indicating the total number of data models in this data provider. protected integer prepareTotalCount ( )return integer Total number of data models in this data provider.

data\ActiveDataProvider prepareKeys()

prepareKeys() protected method Prepares the keys associated with the currently available data models. protected array prepareKeys ( $models )$models array The available data models return array The keys

data\ActiveDataProvider setSort()

setSort() public method Sets the sort definition for this data provider. public void setSort ( $value )$value array|yii\data\Sort|boolean The sort definition to be used by this data provider. This can be one of the following: a configuration array for creating the sort definition object. The "class" element defaults to 'yii\data\Sort' an instance of yii\data\Sort or its subclass false, if sorting needs to be disabled. throws yii\base\InvalidParamException

data\ActiveDataProvider prepareModels()

prepareModels() protected method Prepares the data models that will be made available in the current page. protected array prepareModels ( )return array The available data models

data\ActiveDataProvider $db

$db public property The DB connection object or the application component ID of the DB connection. If not set, the default DB connection will be used. Starting from version 2.0.2, this can also be a configuration array for creating the object. public yii\db\Connection|array|string $db = null

data\ActiveDataProvider $key

$key public property The column that is used as the key of the data models. This can be either a column name, or a callable that returns the key value of a given data model. If this is not set, the following rules will be used to determine the keys of the data models: If $query is an yii\db\ActiveQuery instance, the primary keys of yii\db\ActiveQuery::$modelClass will be used. Otherwise, the keys of the $models array will be used. See also getKeys(). public string|callable $key = null

data\ActiveDataProvider init()

init() public method Initializes the DB connection component. This method will initialize the $db property to make sure it refers to a valid DB connection. public void init ( )throws yii\base\InvalidConfigException if $db is invalid.

data\ActiveDataProvider $query

$query public property The query that is used to fetch data models and $totalCount if it is not explicitly set. public yii\db\QueryInterface $query = null

Database Migration

Creating Migrations Generating Migrations Applying Migrations Reverting Migrations Redoing Migrations Listing Migrations Modifying Migration History Customizing Migrations Migrating Multiple Databases During the course of developing and maintaining a database-driven application, the structure of the database being used evolves just like the source code does. For example, during the development of an application, a new table may be found necessary; after the application is deployed to productio

Database Access Objects

Creating DB Connections Executing SQL Queries Quoting Table and Column Names Performing Transactions Replication and Read-Write Splitting Working with Database Schema Built on top of PDO, Yii DAO (Database Access Objects) provides an object-oriented API for accessing relational databases. It is the foundation for other more advanced database access methods, including query builder and active record. When using Yii DAO, you mainly need to deal with plain SQLs and PHP arrays. As a result, it is