PHP code example of intersvyaz / yii2-tag-dependency-helper
1. Go to this page and download the library: Download intersvyaz/yii2-tag-dependency-helper library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
intersvyaz / yii2-tag-dependency-helper example snippets
php
use Intersvyaz\TagDependencyHelper\ActiveRecordCacheTags;
...
$models = Configurable::getDb()->cache(
function ($db) {
return Configurable::find()->all($db);
},
86400,
new TagDependency([
'tags' => [ActiveRecordCacheTags::getCommonTag(Configurable::className())],
])
);
php
use Intersvyaz\TagDependencyHelper\ActiveRecordCacheTags;
...
$cacheKey = 'Product:' . $model_id;
if (false === $product = Yii::$app->cache->get($cacheKey)) {
if (null === $product = Product::findOne($model_id)) {
throw new NotFoundHttpException;
}
Yii::$app->cache->set(
$cacheKey,
$product,
86400,
new TagDependency(
[
'tags' => [
ActiveRecordCacheTags::getObjectTag(Product::class, $model_id),
]
]
)
);
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.