1. Go to this page and download the library: Download yiier/yii2-action-store 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/ */
yiier / yii2-action-store example snippets
use yiier\actionStore\actions\ActionAction;
class TopicController extends Controller
{
public function actions()
{
return [
'do' => [
'class' => ActionAction::className(),
'pairsType' => ['want','own'], // Optional,default ['like', 'dislike']
'counterType' => ['apply'], // Optional,default ['view', 'clap']
'successCallable' => function ($model){ }, // Optional
'returnCallable' => function ($model){ return $model; }, // Optional
]
];
}
}
namespace common\models;
use yiier\actionStore\models\ActionStore;
class ActionStoreSearch extends ActionStore
{
public function getCompany()
{
return $this->hasOne(Company::className(), ['id' => 'model_id']);
}
}
use common\models\ActionStoreSearch;
class TopicController extends Controller
{
public function actionFavorite()
{
$dataProvider = new ActiveDataProvider([
'query' => ActionStoreSearch::find()
->joinWith('company')
->where(['user_id' => Yii::$app->user->id, 'type' => 'favorite']),
'pagination' => [
'pageSize' => 10,
],
]);
return $this->render('favorite', [
'dataProvider' => $dataProvider,
]);
}
}