Skip to content

Commit 66f98b2

Browse files
author
Igor Chepurnoy
committed
added "verbFilterConfig" property to ManageController, update README
1 parent bccc58d commit 66f98b2

File tree

2 files changed

+21
-46
lines changed

2 files changed

+21
-46
lines changed

README.md

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ php composer.phar require --prefer-dist yii2mod/yii2-comments "*"
2121

2222
or add
2323

24-
```json
24+
```
2525
"yii2mod/yii2-comments": "*"
2626
```
2727

@@ -51,40 +51,17 @@ To access the module, you need to add the following code to your application con
5151
]
5252
```
5353

54-
**Comments management section setup**
55-
56-
To access the comments management section, you need to add the following code to your application configuration:
57-
```php
58-
'controllerMap' => [
59-
'comments' => 'yii2mod\comments\controllers\ManageController',
60-
// Also you can override some controller properties in following way:
61-
'comments' => [
62-
'class' => 'yii2mod\comments\controllers\ManageController',
63-
'searchClass' => [
64-
'class' => 'yii2mod\comments\models\search\CommentSearch',
65-
'pageSize' => 25
66-
],
67-
'indexView' => 'custom path to index view file',
68-
'updateView' => 'custom path to update view file',
69-
],
70-
]
71-
```
72-
> Basically the above code must be placed in the `admin` module
73-
74-
You can then access to management section through the following URL:
54+
Now you can access to management section through the following URL:
7555
http://localhost/path/to/index.php?r=comments/index
7656

77-
> If you have added this controller in the module admin, the URL will look like the following
78-
> http://localhost/path/to/index.php?r=admin/comments/index
79-
8057
> By default only users with `admin` role have access to comments management section. But, you can override `accessControlConfig` property for ManageController.
8158
8259
**Notes:**
83-
> 1) Delete button visible only for user with `admin` role.
60+
> 1) Delete button visible only for users with `admin` role.
8461
8562
> 2) When you delete a comment, all nested comments will be marked as `deleted`.
8663
87-
> 3) For change the any function in the CommentModel you can create your own model and change the property `commentModelClass` in the Comment Module.
64+
> 3) You can override default CommentModel class by changing the property `commentModelClass` in the Comment Module.
8865
8966
> 4) You can implement your own methods `getAvatar` and `getUsername` in the `userIdentityClass`. Just create this methods in your User model. For example:
9067
@@ -154,20 +131,14 @@ $model = Post::find()->where(['title' => 'some post title'])->one();
154131
'model' => $model,
155132
'relatedTo' => 'User ' . \Yii::$app->user->identity->username . ' commented on the page ' . \yii\helpers\Url::current(),
156133
'maxLevel' => 2,
157-
// set `pageSize` with custom sorting
158-
'dataProviderConfig' => [
159-
'sort' => [
160-
'attributes' => ['id'],
161-
'defaultOrder' => ['id' => SORT_DESC],
162-
],
134+
'dataProviderConfig' => [
163135
'pagination' => [
164136
'pageSize' => 10
165137
],
166138
],
167-
// your own config for comments ListView, for example:
168139
'listViewConfig' => [
169140
'emptyText' => Yii::t('app', 'No comments found.'),
170-
]
141+
],
171142
]); ?>
172143
```
173144

controllers/ManageController.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace yii2mod\comments\controllers;
44

55
use Yii;
6-
use yii\filters\VerbFilter;
76
use yii\web\Controller;
87
use yii\web\NotFoundHttpException;
98
use yii2mod\comments\models\CommentModel;
@@ -33,6 +32,18 @@ class ManageController extends Controller
3332
*/
3433
public $searchClass = 'yii2mod\comments\models\search\CommentSearch';
3534

35+
/**
36+
* @var array verb filter config
37+
*/
38+
public $verbFilterConfig = [
39+
'class' => 'yii\filters\VerbFilter',
40+
'actions' => [
41+
'index' => ['get'],
42+
'update' => ['get', 'post'],
43+
'delete' => ['post'],
44+
],
45+
];
46+
3647
/**
3748
* @var array access control config
3849
*/
@@ -52,14 +63,7 @@ class ManageController extends Controller
5263
public function behaviors()
5364
{
5465
return [
55-
'verbs' => [
56-
'class' => VerbFilter::class,
57-
'actions' => [
58-
'index' => ['get'],
59-
'update' => ['get', 'post'],
60-
'delete' => ['post'],
61-
],
62-
],
66+
'verbs' => $this->verbFilterConfig,
6367
'access' => $this->accessControlConfig,
6468
];
6569
}
@@ -83,7 +87,7 @@ public function actionIndex()
8387
}
8488

8589
/**
86-
* Updates an existing CommentModel model.
90+
* Updates an existing CommentModel.
8791
*
8892
* If update is successful, the browser will be redirected to the 'index' page.
8993
*
@@ -124,7 +128,7 @@ public function actionDelete($id)
124128
}
125129

126130
/**
127-
* Finds the CommentModel model based on its primary key value.
131+
* Finds the CommentModel based on its primary key value.
128132
*
129133
* If the model is not found, a 404 HTTP exception will be thrown.
130134
*

0 commit comments

Comments
 (0)