dev-master
9999999-dev https://github.com/yiiext/comment-moduleModule that adds comments to your application. You can add comments on any AR Model you like.
BSD-3-Clause
The Requires
- php >=5.1.0
- yiisoft/yii 1.1.*
extension yii comments
Module that adds comments to your application. You can add comments on any AR Model you like.
makes every entity of your application commentable. Features:, (*1)
If there is something missing here, or you think one step should be described more detailed, please report it. Thanks!, (*2)
There are two ways to get this extension working:, (*3)
Clone repo:, (*4)
protected
in default yii webapp).git clone https://github.com/yiiext/comment-module.git extensions/comment-module
git submodule add https://github.com/yiiext/comment-module.git protected/extensions/comment-module
git submodule update --init
to get the gravatar extension that's included.Download latest release and put all the files into
extensions/comment-module
under your application baseDir (protected
in default yii webapp).
To be able to use Gravatar support you have to copy YiiGravatar.php
into extensions/comment-module/extensions/gravatar
., (*5)
Add module to your application config (optional config values are commented):, (*6)
array( // ... 'comment'=>array( 'class'=>'ext.comment-module.CommentModule', 'commentableModels'=>array( // define commentable Models here (key is an alias that must be lower case, value is the model class name) 'post'=>'Post' ), // set this to the class name of the model that represents your users 'userModelClass'=>'User', // set this to the username attribute of User model class 'userNameAttribute'=>'username', // set this to the email attribute of User model class 'userEmailAttribute'=>'email', // you can set controller filters that will be added to the comment controller {@see CController::filters()} // 'controllerFilters'=>array(), // you can set accessRules that will be added to the comment controller {@see CController::accessRules()} // 'controllerAccessRules'=>array(), // you can extend comment class and use your extended one, set path alias here // 'commentModelClass'=>'comment.models.Comment', ), // ... ), // ... ~~~ Create database tables: You can use the database migration provieded by this extension or create a table (example for mysql): ~~~sql CREATE TABLE IF NOT EXISTS `comments` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, `message` text COLLATE utf8_unicode_ci, `userId` int(11) UNSIGNED DEFAULT NULL, `createDate` datetime DEFAULT NULL, PRIMARY KEY (`id`), KEY `fk_comments_userId` (`userId`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; ~~~ You might also want to add a foreign key for `userId` column that references you user tables pk. Create a database table for every commentable Model relation: ~~~sql CREATE TABLE IF NOT EXISTS `posts_comments_nm` ( `postId` int(11) UNSIGNED NOT NULL, `commentId` int(11) UNSIGNED NOT NULL, PRIMARY KEY (`postId`,`commentId`), KEY `fk_posts_comments_comments` (`commentId`), KEY `fk_posts_comments_posts` (`postId`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; ~~~ You might want to add foreign keys here too. Add commentable behavior to all Models you want to be commented. ~~~php array( 'class' => 'ext.comment-module.behaviors.CommentableBehavior', // name of the table created in last step 'mapTable' => 'posts_comments_nm', // name of column to related model id in mapTable 'mapRelatedColumn' => 'postId' ), ); } ~~~ Finally add comments to your view template of the commentable model: ~~~phpcomments
renderPartial('comment.views.comment.commentList', array( 'model'=>$model )); ?>
Comment module raises events to which you can attach event handlers to handle them. See The Definitive Guide to Yii on how to do this., (*7)
You can also attach behaviors
to CommentModule by setting 'behaviors'=>array(/* ... */)
in the module config described above.
See CModule::behaviors on how to add behaviors to a module., (*8)
This event is raised when a new comment has been saved.
The following attributes are available on the $event
given as the first parameter to the event handler:, (*9)
$event->comment
is the ActiveRecord instance of the currently added comment.$event->commentedModel
is the model the comment was added to.Possible use cases:, (*10)
This event is raised when a user edited a comment.
The following attributes are available on the $event
given as the first parameter to the event handler:, (*11)
$event->comment
is the ActiveRecord instance of the updated comment.This event is raised when a user deleted a comment.
The following attributes are available on the $event
given as the first parameter to the event handler:, (*12)
$event->comment
is the ActiveRecord instance of the deleted comment.Module that adds comments to your application. You can add comments on any AR Model you like.
BSD-3-Clause
extension yii comments