PHP code example of dgoriaev / yii2-comments

1. Go to this page and download the library: Download dgoriaev/yii2-comments 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/ */

    

dgoriaev / yii2-comments example snippets


php yii migrate --migrationPath=@vendor/yii2mod/yii2-comments/migrations

'modules' => [
    'comment' => [
        'class' => 'yii2mod\comments\Module',
    ],
]


public function getAvatar()
{
    // your custom code
}

public function getUsername()
{
    // your custom code
}


// the model to which are added comments, for example:
$model = Post::find()->where(['title' => 'some post title'])->one();

 echo \yii2mod\comments\widgets\Comment::widget([
    'model' => $model,
]); 

 echo \yii2mod\comments\widgets\Comment::widget([
    'model' => $model,
    'commentView' => '@app/views/site/comments/index' // path to your template
]); 

 echo \yii2mod\comments\widgets\Comment::widget([
        'model' => $model,
]); 

 echo \yii2mod\comments\widgets\Comment::widget([
      'model' => $model,
      'dataProviderConfig' => [
          'pagination' => [
              'pageSize' => 10
          ],
      ]
]); 

 echo \yii2mod\comments\widgets\Comment::widget([
      'model' => $model,
      'relatedTo' => 'User ' . \Yii::$app->user->identity->username . ' commented on the page ' . \yii\helpers\Url::current(),
      'maxLevel' => 2,
      'dataProviderConfig' => [
          'pagination' => [
              'pageSize' => 10
          ],
      ],
      'listViewConfig' => [
          'emptyText' => Yii::t('app', 'No comments found.'),
      ],
]); 

'modules' => [
    'comment' => [
        'class' => 'yii2mod\comments\Module',
        'controllerMap' => [
            'default' => [
                'class' => 'yii2mod\comments\controllers\DefaultController',
                'on beforeCreate' => function ($event) {
                    $event->getCommentModel();
                    // your custom code
                },
                'on afterCreate' => function ($event) {
                    $event->getCommentModel();
                    // your custom code
                },
                'on beforeDelete' => function ($event) {
                    $event->getCommentModel();
                    // your custom code
                },
                'on afterDelete' => function ($event) {
                    $event->getCommentModel();
                    // your custom code
                },
            ]
        ]
    ]
]

return [
    'components' => [
        'i18n' => [
            'translations' => [
                'yii2mod.comments' => [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'basePath' => '@yii2mod/comments/messages',
                ],
                // ...
            ],
        ],
        // ...
    ],
    // ...
];

php composer.phar