PHP code example of coderseden / cmt

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

    

coderseden / cmt example snippets


php yii migrate --migrationPath=@vendor/coderseden/cmt/migrations

'modules' => [
    'comment' => [
        'class' => 'coderseden\cmt\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 \coderseden\cmt\widgets\Comment::widget([
    'model' => $model,
]); 

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

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

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

 echo \coderseden\cmt\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' => 'coderseden\cmt\Module',
        'controllerMap' => [
            'default' => [
                'class' => 'coderseden\cmt\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