Answer the question
In order to leave comments, you need to log in
How to make a universal independent module in yii2?
Actually, there are several modules:
- Articles
- Testimonials
- Gallery
...
I would like to create a common comments module that could be used for any module.
To do this, there are 2 fields in the comment table:
post-id - comment record identifier
type - comment type (for example, the comment belongs to the articles module)
During development, I had 1 problem.
I display comments using a widget, there is also a list of comments and a form / forms for adding comments.
For example, we will work with the Articles module
<?php
echo frontend\modules\comments\widgets\CommentsList::widget([
'find' => ['post_id'=>$article->article_id, 'type'=>'article'],
]);
?>
<?php
echo frontend\modules\comments\widgets\CommentsList::widget([
'find' => ['post_id'=>$article->article_id, 'type'=>'article'],
'model' => 'common\modules\articles\models\Articles'
]);
?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question