gii\generators\crud\Generator rules()

rules() public method Returns the validation rules for attributes. Validation rules are used by validate() to check if attribute values are valid. Child classes may override this method to declare different validation rules. Each rule is an array with the following structure: [ ['attribute1', 'attribute2'], 'validator type', 'on' => ['scenario1', 'scenario2'], //...other parameters... ] where attribute list: required, specifies the attributes array to be validated, for s

Routing and URL Creation

URL Formats Routing Creating URLs Using Pretty URLs Performance Consideration When a Yii application starts processing a requested URL, the first step it takes is to parse the URL into a route. The route is then used to instantiate the corresponding controller action to handle the request. This whole process is called routing. The reverse process of routing is called URL creation, which creates a URL from a given route and the associated query parameters. When the created URL is later requeste

bootstrap\InputWidget

All Classes | Properties | Methods Inheritance yii\bootstrap\InputWidget » yii\widgets\InputWidget » yii\base\Widget » yii\base\Component » yii\base\Object Implements yii\base\Configurable, yii\base\ViewContextInterface Uses Traits yii\bootstrap\BootstrapWidgetTrait Subclasses yii\bootstrap\ToggleButtonGroup Available since version 2.0.6 Source Code https://github.com/yiisoft/yii2-bootstrap/blob/master/InputWidget.php InputWidget is an adjusted for bootstrap needs version of yii\widget

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

Internationalization

Locale and Language Message Translation Message Formatting View Translation Formatting Date and Number Values Setting Up PHP Environment Internationalization (I18N) refers to the process of designing a software application so that it can be adapted to various languages and regions without engineering changes. For Web applications, this is of particular importance because the potential users may be worldwide. Yii offers a full spectrum of I18N features that support message translation, view tra

Query Builder

Building Queries Query Methods Built on top of Database Access Objects, query builder allows you to construct a SQL query in a programmatic and DBMS-agnostic way. Compared to writing raw SQL statements, using query builder will help you write more readable SQL-related code and generate more secure SQL statements. Using query builder usually involves two steps: Build a yii\db\Query object to represent different parts (e.g. SELECT, FROM) of a SELECT SQL statement. Execute a query method (e.g. a

Console applications

Usage The entry script Configuration Creating your own console commands Besides the rich features for building web applications, Yii also has full-featured support for console applications which are mainly used to create background and maintenance tasks that need to be performed for a website. The structure of console applications is very similar to a Yii web application. It consists of one or more yii\console\Controller classes, which are often referred to as commands in the console environme

Shared Hosting Environment

Deploying a basic project template Deploying an advanced project template Shared hosting environments are often quite limited about configuration and directory structure. Still in most cases you can run Yii 2.0 on a shared hosting environment with a few adjustments. Deploying a basic project template Since in a shared hosting environment there's typically only one webroot, use the basic project template if you can. Refer to the Installing Yii chapter and install the basic project template lo

web\AssetManager publish()

publish() public method Publishes a file or a directory. This method will copy the specified file or directory to $basePath so that it can be accessed via the Web server. If the asset is a file, its file modification time will be checked to avoid unnecessary file copying. If the asset is a directory, all files and subdirectories under it will be published recursively. Note, in case $forceCopy is false the method only checks the existence of the target directory to avoid repetitive copying (

db\ColumnSchema $enumValues

$enumValues public property Enumerable values. This is set only if the column is declared to be an enumerable type. public array $enumValues = null