This module helps to add comments to any instance of CActiveRecord.
tested on Yii 1.1.8
You must create table
CREATE TABLE IF NOT EXISTS `tbl_comments` ( `owner_name` varchar(50) NOT NULL, `owner_id` int(12) NOT NULL, `comment_id` int(12) NOT NULL AUTO_INCREMENT, `parent_comment_id` int(12) DEFAULT NULL, `creator_id` int(12) DEFAULT NULL, `user_name` varchar(128) DEFAULT NULL, `user_email` varchar(128) DEFAULT NULL, `comment_text` text, `create_time` int(11) DEFAULT NULL, `update_time` int(11) DEFAULT NULL, `status` int(1) NOT NULL DEFAULT '0', PRIMARY KEY (`comment_id`), KEY `owner_name` (`owner_name`,`owner_id`) )
To add a comment to the model, you need to perform two steps. First step - configure the module in app config:
'modules'=>array( ... 'comments'=>array( //you may override default config for all connecting models 'defaultModelConfig' => array( //only registered users can post comments 'registeredOnly' => false, 'useCaptcha' => false, //allow comment tree 'allowSubcommenting' => true, //display comments after moderation 'premoderate' => false, //action for postig comment 'postCommentAction' => 'comments/comment/postComment', //super user condition(display comment list in admin view and automoderate comments) 'isSuperuser'=>'Yii::app()->user->checkAccess("moderate")', //order direction for comments 'orderComments'=>'DESC', ), //the models for commenting 'commentableModels'=>array( //model with individual settings 'Citys'=>array( 'registeredOnly'=>true, 'useCaptcha'=>true, 'allowSubcommenting'=>false, //config for create link to view model page(page with comments) 'pageUrl'=>array( 'route'=>'admin/citys/view', 'data'=>array('id'=>'city_id'), ), ), //model with default settings 'ImpressionSet', ), //config for user models, which is used in application 'userConfig'=>array( 'class'=>'User', 'nameProperty'=>'username', 'emailProperty'=>'email', ), ), ... ),
Second step - display ECommentListWidget in view for displaying commentable models
$this->widget('comments.widgets.ECommentsListWidget', array( 'model' => $model, ));
To manage all comments go to http://yoursite.com/comments.
Total 14 comments
For beginners - it would have been great if you had mentioned the folder where we need to extract this module.
Does this go into the modules or extension folder ?
thanks for replying and thanks for the module!
Great!
segoddnja you made my day, this module is just great
When your module use as child module, it doesn't works. I post the problems and my solution here:
http://www.yiiframework.com/forum/index.php/topic/37855-problems-with-nested-modules/
Подскажите пожалуйста как использовать этот модуль в моделях с составными ключами. По исходникам, как я понимаю, это возможно. А вот как связать в конфиге - непонятно
Вот кусок моего файла настроек этого модуля:
где модель User имеет геттер getLink(), который выводит фото пользователя с его ником сразу в виде ссылки. Email не отображается.
на 75 строке базового виджета ECommentsBaseWidget Исправила
Вроде бы заработало.
А можно ли с помощью настроек убрать email из имен? Или надо править view?
Скорее всего, у тебя на странице есть еще как минимум один CHtml::ajax элемент. В этом случае получаем 2 (или больше) элемента с одинаковыми id, а именно с #yw0. Решение: генерируй уникальные id для всех CHtml::ajax-элементов, например с помощью uniqid().
Получаю ошибку TypeError: jQuery("#yw0").commentsList is not a function
В FireBug вижу что скрипт подключен
В чем может быть дело? Thanks
I've just completed a similar comment module and.. hehe no just kidding..
Nice approach though, linking comments to a class.
I also have created a comments module, but havent posted it yet :) I has similar approach, but has ajax support ;) It also has callback support, if you want to know when a comment is inserted.
congrats ! this is badly needed for almost every projects , but need a well wrapper module ,and make it a module is the best way when using it just use a widget as interface. in yiiext early i noticed that there is a commentable behavior but it is needed to inject to models. i don't think it is a good idea. and here is my comment schema:
by the way , @CeBe did you use the smarty as view render. i read your comment-module in github. what if some project use another viewRender ? i thought yours is more complex for using .
I just created an extension for exactly the same approach yesterday! :-) https://github.com/yiiext/comment-module
Edit: it is now here: /extension/comment-module
Leave a comment
Please login to leave your comment.