yii2mod / yii2-comments

Comments module for Yii2
MIT License
159 stars 64 forks source link

how to entry entity , entityId, and relatedTo #15

Closed dzas42 closed 8 years ago

dzas42 commented 8 years ago

when i used this widget ,, the first show error 'The "entityIdAttribute" value for widget model cannot be empty,,, and widgets there are column entity , entitiyId and relatedTo,, how to use entry this column

ihorchepurnyi commented 8 years ago

Hi, please describe in more details the issue

ihorchepurnyi commented 8 years ago

Your model must have a primary key column, by default widget used the id attribute from your model. If the primary key in your model has another name, then you can change the name of entityIdAttribute by the following code:

<?php echo \yii2mod\comments\widgets\Comment::widget([
    'model' => $model,
    'entityIdAttribute' => 'name of primary key attribute from your model'
]); ?>
dzas42 commented 8 years ago

that is work but button delete and replay is not work and pjax is not working ![Uploading error.png…]() in firebug error TypeError: jQuery(...).comment is not a function jQuery('#comment-form').comment({"pjaxContainerId":"#","formSelector":"#comment-...

ihorchepurnyi commented 8 years ago

How i can reproduce it? Can you add your code with model and widget setup here?

ihorchepurnyi commented 8 years ago

Now i try the following code and the reply and delete functionality works perfectly.

$model = CmsModel::findOne(1);

<?php echo Comment::widget([
            'model' => $model,
            'entityIdAttribute' => 'idkey'
        ]); ?>
dzas42 commented 8 years ago

// in view <?php

echo \yii2mod\comments\widgets\Comment::widget([ 'model' => $model, 'entityIdAttribute' => 'id' //'entity'=>'test', // 'entityId'=>1, ]);

// in model $model = \yii2mod\comments\models\CommentModel::findOne(1); but this is same error,,,

ihorchepurnyi commented 8 years ago

$model is an entity to which a comment is added. For example Post, Cms, etc..

ihorchepurnyi commented 8 years ago

For example, if you want to add the comments to the some post you can try the following code:

$model = Post::find()->where(['title' => 'some post title'])->one();
 // and just put your model to the widget.
<?php echo \yii2mod\comments\widgets\Comment::widget([
        'model' => $model,
 ]);