Generating Code with Gii

Starting Gii Generating an Active Record Class Generating CRUD Code Trying it Out Summary This section will describe how to use Gii to automatically generate code that implements some common Web site features. Using Gii to auto-generate code is simply a matter of entering the right information per the instructions shown on the Gii Web pages. Through this tutorial, you will learn how to: enable Gii in your application, use Gii to generate an Active Record class, use Gii to generate the code imp

Fragment Caching

Caching Options Nested Caching Dynamic Content Fragment caching refers to caching a fragment of a Web page. For example, if a page displays a summary of yearly sale in a table, you can store this table in cache to eliminate the time needed to generate this table for each request. Fragment caching is built on top of data caching. To use fragment caching, use the following construct in a view: if ($this->beginCache($id)) { // ... generate content here ... $this->endCache(); } Th

Fixtures

Defining a Fixture Using Fixtures Defining and Using Global Fixtures Organizing Fixture Classes and Data Files Summary Fixtures format Loading fixtures Unloading fixtures Configure Command Globally Auto-generating fixtures Fixtures are an important part of testing. Their main purpose is to set up the environment in a fixed/known state so that your tests are repeatable and run in an expected way. Yii provides a fixture framework that allows you to define your fixtures precisely and use them eas

filters\VerbFilter events()

events() public method Declares event handlers for the $owner's events. public array events ( )return array Events (array keys) and the corresponding event handler methods (array values).

filters\VerbFilter beforeAction()

beforeAction() public method public boolean beforeAction ( $event )$event yii\base\ActionEvent throws yii\web\MethodNotAllowedHttpException when the request method is not allowed.

filters\VerbFilter $actions

$actions public property This property defines the allowed request methods for each action. For each action that should only support limited set of request methods you add an entry with the action id as array key and an array of allowed methods (e.g. GET, HEAD, PUT) as the value. If an action is not listed all request methods are considered allowed. You can use '*' to stand for all actions. When an action is explicitly specified, it takes precedence over the specification given by '*'. For

filters\RateLimitInterface saveAllowance()

saveAllowance() public abstract method Saves the number of allowed requests and the corresponding timestamp to a persistent storage. public abstract void saveAllowance ( $request, $action, $allowance, $timestamp )$request yii\web\Request The current request $action yii\base\Action The action to be executed $allowance integer The number of allowed requests remaining. $timestamp integer The current timestamp.

filters\RateLimitInterface loadAllowance()

loadAllowance() public abstract method Loads the number of allowed requests and the corresponding timestamp from a persistent storage. public abstract array loadAllowance ( $request, $action )$request yii\web\Request The current request $action yii\base\Action The action to be executed return array An array of two elements. The first element is the number of allowed requests, and the second element is the corresponding UNIX timestamp.

filters\RateLimitInterface getRateLimit()

getRateLimit() public abstract method Returns the maximum number of allowed requests and the window size. public abstract array getRateLimit ( $request, $action )$request yii\web\Request The current request $action yii\base\Action The action to be executed return array An array of two elements. The first element is the maximum number of allowed requests, and the second element is the size of the window in seconds.

filters\RateLimiter checkRateLimit()

checkRateLimit() public method Checks whether the rate limit exceeds. public void checkRateLimit ( $user, $request, $response, $action )$user yii\filters\RateLimitInterface The current user $request yii\web\Request $response yii\web\Response $action yii\base\Action The action to be executed throws yii\web\TooManyRequestsHttpException if rate limit exceeds