elephantsgroup / eg-follow
yii2 关注模块
1.0.1
2018-06-08 19:01 UTC
Requires
This package is not auto-updated.
Last update: 2024-09-18 20:23:05 UTC
README
要使用Elephants Group关注模块,首先您必须安装模块,然后在您的网站上任何地方都可以使用关注小部件。
安装步骤
- 运行
php composer.phar require elephantsgroup/eg-follow "*"
或将 "elephantsgroup/eg-follow": "*" 添加到您的 composer.json 文件的 require 部分。
- 迁移数据库
yii migrate --migrationPath=vendor/elephantsgroup/eg-follow/migrations
- 将关注模块添加到公共配置(common/config.php 文件)
...
'follow' => [
'class' => 'elephantsGroup\follow\Module',
],
...
]```
4) open access to module in common configuration
```'as access' => [
'class' => 'mdm\admin\components\AccessControl',
'allowActions' => [
...
'follow/ajax/*',
...
]
]```
5) filter admin controller in frontend configuration (frontend/config.php file)
```'modules' => [
...
'follow' => [
'as frontend' => 'elephantsGroup\follow\filters\FrontendFilter',
],
...
]```
5) filter ajax controller in backend configuration (backend/config.php file)
```'modules' => [
...
'follow' => [
'as backend' => 'elephantsGroup\follow\filters\BackendFilter',
],
...
]```
Using follow widget
===
Anywhere in your code you can use follow widget as follows:
```<?= Follows::widget() ?>```
You need to use Follows widget header in your page:
```use elephantsGroup\follow\components\Follows;```
Follow widget parameters
---
- item (integer): to separate follows between different items.
```<?= Follows::widget(['item' => 1]) ?>```
```<?= Follows::widget(['item' => $model->id]) ?>```
default value for item is 0
- service (integer): to separate follows between various item types.
```<?= Folloes::widget(['service' => 1, 'item' => $model->id]) ?>```
for example you can use different values for different modules in your app, and then use follow widget separately in modules.
default value for service is 0
- color (string): color of unfollowed icon heart, default 'black'
```<?= Follows::widget(['service' => 1, ''item' => $model->id, 'color' => 'yellow']) ?>```
- view_file (string): the view file path for rendering
```<?= Follows::widget([
'service' => 1,
'item' => $model->id,
'color' => 'yellow',
'view_file' => Yii::getAlias('@frontend') . '/views/follow/widget.php'
]) ?>```
you can use these variables in your customized view:
* service
* item
* color
* is_follow