N
N
nepster-web2014-06-10 17:36:39
Yii
nepster-web, 2014-06-10 17:36:39

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'],
                ]);
            ?>

Comments shown on the page, all is well. BUT now when I need to write a comment and the data of the new comment gets into the comment controller action, I lose the connection to which module the comment was sent to.
Previously, I was thinking of doing something like this
<?php   
                echo frontend\modules\comments\widgets\CommentsList::widget([
                    'find'  => ['post_id'=>$article->article_id, 'type'=>'article'],
                    'model' => 'common\modules\articles\models\Articles'
                ]);
            ?>

That is, I drag the class of the Article module along with it, I also pull it into the form and pass it as a regular post string and work with it. But it's not the best option. Can you please tell me how can I implement my task correctly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2014-06-10
Protko @Fesor

if you have a table - you already have a hard binding to the modules. If you want to make it universal - make an abstract comment model that you need to implement (for example, tableName or whatever it is now, and add links).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question