Download the PHP package narekmarkosyan/yii2-html-cache without Composer
On this page you can find all versions of the php package narekmarkosyan/yii2-html-cache. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download narekmarkosyan/yii2-html-cache
More information about narekmarkosyan/yii2-html-cache
Files in narekmarkosyan/yii2-html-cache
Informations about the package yii2-html-cache
Yii2 HTML cache
Yii2 HTML Cache generates cache file with FULL HTML of your action from DOCTYPE
to </html>
.
This is an extension for Yii 2.x, if you have Yii 1.x use Yii HTML Cache
Instalation
Run
or add
to require
section of your composer.json
.
Add following to your components
in configs
Usage
Add following code at the beginning of beforeAction
method in your controller
Where $action
is a first parameter of beforeAction
. Or if you don't have beforeAction
add the following code to your controller
Add the following code at the end of renderContent
method in your controller
Where $output
is a first parameter of renderContent
. Or if you don't have renderContent
add the following code to your controller
Settings
- lifeTime - lifetime of generated cache in seconds. Default: 1 day
- extra_params - parameters in controller that can affect your final HTML. For example, if you have an action with product description and it variates for different
id_product
, addextra_params => array('id_product')
to configs - disabled -
true
if disabled,false
if enabled. Default: false - excluded_actions - Actions list that doesn't need to be cached in
array('controller_id'=> array('action1', 'action2'))
format. - excluded_params - Params list that doesn't need to be cached if they exist and are equal to exact value. If value not set then checking should not be a false.
NOTE 1: in
excluded_params
you need to store Controller variables, not$_GET/$_POST/$_REQUEST
variablesNOTE 2: you can add excluded action or parameter from controller by calling
excludeActions
andexcludeParams
methods. See Additional features section
Additional features
There are few additional methods you can use in your controller.
directReplace
If you have some parts in your HTML that need to be loaded dynamically in cache you can use placeholders in view and then replace them with directReplace
method.
Params
There are two ways for parameters
- string
$replace_key
- key that needs to be replaced - string
$value
- HTML part that needs to be placed instead of placeholder
OR
- array
$replace_array
- array with$replace_key => $value
Usage
In view
In beforeAction
method of your controller
NOTE: placeholder always needs to be UPPERCASE and in {BRACES}
excludeActions
Adding action to the list of excluded actions.
Params
- CController
$controller
- Controller of actions - string|array
$actions
- name of action or list of actions
Usage
In beforeAction
method of your controller
allowActions
Removes action from excluded actions list.
Params
- CController
$controller
- Controller of actions - string|array
$actions
- name of action or list of actions
Usage
In beforeAction
method of your controller
excludeParams
Adding params to the list of excluded params.
Params
- CController
$controller
- Controller of actions - string|array
$params
- name of param or list of params
Usage
In beforeAction
method of your controller
allowParams
Removes params from the list of excluded params
Params
- CController
$controller
- Controller of actions - string|array
$params
- name of param or list of params
Usage
In beforeAction
method of your controller
FAQ
I'm doing everythink like described but it doesn't work.
hmm...