Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 176 lines (136 sloc) 6.655 kB
3a96eb5 @cebe copied files from code dashboard
cebe authored
1 Comment module
2 --------------
3
4 makes every entity of your application commentable.
9365531 @cebe created README file
cebe authored
5 Features:
1abe14f @cebe cleanup comment controller
cebe authored
6
929699d @cebe add update action + events for upd/delete close #4
cebe authored
7 * Create, Update, Delete comments with ajax
9365531 @cebe created README file
cebe authored
8 * Gravatar support
9 * define multiple models that can be commented
929699d @cebe add update action + events for upd/delete close #4
cebe authored
10 * Events raised on new, update, delete
9365531 @cebe created README file
cebe authored
11 * more coming soon...
3a96eb5 @cebe copied files from code dashboard
cebe authored
12
1abe14f @cebe cleanup comment controller
cebe authored
13 If there is something missing here, or you think one step should be described more detailed,
14 please [report it](https://github.com/yiiext/comment-module/issues/new). Thanks!
15
e71e216 @cebe added requirements to readme
cebe authored
16 Requirements
17 ------------
18
19 * Tested with Yii 1.1.8, should work in earlier versions
20 * [yii-gravatar extension](https://github.com/malyshev/yii-gravatar) for gravatar support
21
9365531 @cebe created README file
cebe authored
22 Resources
23 ---------
24
25 * Found a bug or want a feature? [Report it on github](https://github.com/yiiext/comment-module/issues)
26 * [Code on github](https://github.com/yiiext/comment-module)
27 * E-Mail the author: CeBe <[mail@cebe.cc](mailto:mail@cebe.cc)>
02caa34 @cebe added demo to readme
cebe authored
28 * demo on [http://demo.cebe.cc/comment-module](http://demo.cebe.cc/comment-module)
9365531 @cebe created README file
cebe authored
29
ab43c00 @cebe updated readme download section
cebe authored
30 Download
31 --------
32
33 There are two ways to get this extension working:
9365531 @cebe created README file
cebe authored
34
ab43c00 @cebe updated readme download section
cebe authored
35 1. Clone repo:
36 * Go to your application baseDir (`protected` in default yii webapp).
37 * `git clone https://github.com/yiiext/comment-module.git extensions/comment-module`
38 * If your project is in a git repository you can alternatively add comment-module as a submodule like this:
39 * `git submodule add https://github.com/yiiext/comment-module.git protected/extensions/comment-module`
40 * go to new comment-modules base dir and run
41 `git submodule update --init` to get the gravatar extension that's included.
eb4241f @cebe Improved readme readability
cebe authored
42
ab43c00 @cebe updated readme download section
cebe authored
43 2. [Download](https://github.com/yiiext/comment-module/tags) latest release and put all the files into
44 `extensions/comment-module` under your application baseDir (`protected` in default yii webapp).
45 To be able to use Gravatar support you have to copy [YiiGravatar.php](https://github.com/malyshev/yii-gravatar/tree/master/yii-gravatar)
46 into `extensions/comment-module/extensions/gravatar`.
eb4241f @cebe Improved readme readability
cebe authored
47
ab43c00 @cebe updated readme download section
cebe authored
48 Quickstart
49 ----------
9365531 @cebe created README file
cebe authored
50
1abe14f @cebe cleanup comment controller
cebe authored
51 Add module to your application config (optional config values are commented):
eb4241f @cebe Improved readme readability
cebe authored
52
bbf97c3 @cebe fixed readme code hightlights to work with github and CMarkdownparser
cebe authored
53 ~~~php
ba0bfc3 @cebe fixed readme syntax highlighting
cebe authored
54 <?php
9365531 @cebe created README file
cebe authored
55 // ...
56 'modules'=>array(
57 // ...
58 'comment'=>array(
59 'class'=>'ext.comment-module.CommentModule',
60 'commentableModels'=>array(
61 // define commentable Models here (key is an alias that must be lower case, value is the model class name)
62 'post'=>'Post'
63 ),
64 // set this to the class name of the model that represents your users
65 'userModelClass'=>'User',
66 // set this to the username attribute of User model class
67 'userNameAttribute'=>'username',
68 // set this to the email attribute of User model class
1abe14f @cebe cleanup comment controller
cebe authored
69 'userEmailAttribute'=>'email',
70 // you can set controller filters that will be added to the comment controller {@see CController::filters()}
71 // 'controllerFilters'=>array(),
72 // you can set accessRules that will be added to the comment controller {@see CController::accessRules()}
73 // 'controllerAccessRules'=>array(),
97d2d00 @cebe added option to allow replacement of Comment Model
cebe authored
74 // you can extend comment class and use your extended one, set path alias here
e71e216 @cebe added requirements to readme
cebe authored
75 // 'commentModelClass'=>'comment.models.Comment',
9365531 @cebe created README file
cebe authored
76 ),
77 // ...
78 ),
79 // ...
bbf97c3 @cebe fixed readme code hightlights to work with github and CMarkdownparser
cebe authored
80 ~~~
9365531 @cebe created README file
cebe authored
81
82 Create database tables:
83 You can use the database migration provieded by this extension or create a table (example for mysql):
eb4241f @cebe Improved readme readability
cebe authored
84
bbf97c3 @cebe fixed readme code hightlights to work with github and CMarkdownparser
cebe authored
85 ~~~sql
9365531 @cebe created README file
cebe authored
86 CREATE TABLE IF NOT EXISTS `comments` (
87 `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
88 `message` text COLLATE utf8_unicode_ci,
89 `userId` int(11) UNSIGNED DEFAULT NULL,
90 `createDate` datetime DEFAULT NULL,
91 PRIMARY KEY (`id`),
92 KEY `fk_comments_userId` (`userId`)
93 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
bbf97c3 @cebe fixed readme code hightlights to work with github and CMarkdownparser
cebe authored
94 ~~~
9365531 @cebe created README file
cebe authored
95 You might also want to add a foreign key for `userId` column that references you user tables pk.
96
97 Create a database table for every commentable Model relation:
eb4241f @cebe Improved readme readability
cebe authored
98
bbf97c3 @cebe fixed readme code hightlights to work with github and CMarkdownparser
cebe authored
99 ~~~sql
9365531 @cebe created README file
cebe authored
100 CREATE TABLE IF NOT EXISTS `posts_comments_nm` (
101 `postId` int(11) UNSIGNED NOT NULL,
102 `commentId` int(11) UNSIGNED NOT NULL,
7c1b33c @cebe fixed docs closes issue #2
cebe authored
103 PRIMARY KEY (`postId`,`commentId`),
104 KEY `fk_posts_comments_comments` (`commentId`),
105 KEY `fk_posts_comments_posts` (`postId`)
9365531 @cebe created README file
cebe authored
106 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
bbf97c3 @cebe fixed readme code hightlights to work with github and CMarkdownparser
cebe authored
107 ~~~
9365531 @cebe created README file
cebe authored
108 You might want to add foreign keys here too.
109
110 Add commentable behavior to all Models you want to be commented.
eb4241f @cebe Improved readme readability
cebe authored
111
bbf97c3 @cebe fixed readme code hightlights to work with github and CMarkdownparser
cebe authored
112 ~~~php
ba0bfc3 @cebe fixed readme syntax highlighting
cebe authored
113 <?php
114 // ...
9365531 @cebe created README file
cebe authored
115 public function behaviors() {
116 return array(
117 'commentable' => array(
118 'class' => 'ext.comment-module.behaviors.CommentableBehavior',
119 // name of the table created in last step
120 'mapTable' => 'posts_comments_nm',
121 // name of column to related model id in mapTable
122 'mapRelatedColumn' => 'postId'
123 ),
124 );
125 }
bbf97c3 @cebe fixed readme code hightlights to work with github and CMarkdownparser
cebe authored
126 ~~~
9365531 @cebe created README file
cebe authored
127
128 Finally add comments to your view template of the commentable model:
eb4241f @cebe Improved readme readability
cebe authored
129
bbf97c3 @cebe fixed readme code hightlights to work with github and CMarkdownparser
cebe authored
130 ~~~php
9365531 @cebe created README file
cebe authored
131 <h1>comments</h1>
132
133 <?php $this->renderPartial('comment.views.comment.commentList', array(
134 'model'=>$model
135 )); ?>
bbf97c3 @cebe fixed readme code hightlights to work with github and CMarkdownparser
cebe authored
136 ~~~
9365531 @cebe created README file
cebe authored
137
2a389bd @cebe added onNewComment-Event to CommentModule
cebe authored
138
139 Extending Comment-Module
140 ------------------------
141
142 Comment module raises [events](http://www.yiiframework.com/doc/guide/1.1/en/basics.component#component-event)
143 to which you can attach event handlers to handle them.
144 See [The Definitive Guide to Yii](http://www.yiiframework.com/doc/guide/1.1/en/basics.component#component-event) on how to do this.
145
146 You can also attach [behaviors](http://www.yiiframework.com/doc/guide/1.1/en/basics.component#component-behavior)
e664c0e @cebe some readme fixes
cebe authored
147 to CommentModule by setting `'behaviors'=>array(/* ... */)` in the module config described above.
2a389bd @cebe added onNewComment-Event to CommentModule
cebe authored
148 See [CModule::behaviors](http://www.yiiframework.com/doc/api/1.1/CModule#behaviors-detail) on how to add behaviors to a module.
149
150 ### onNewComment
151
152 This event is raised when a new comment has been saved.
e664c0e @cebe some readme fixes
cebe authored
153 The following attributes are available on the `$event` given as the first parameter to the event handler:
2a389bd @cebe added onNewComment-Event to CommentModule
cebe authored
154
929699d @cebe add update action + events for upd/delete close #4
cebe authored
155 * `$event->comment` is the ActiveRecord instance of the currently added comment.
2a389bd @cebe added onNewComment-Event to CommentModule
cebe authored
156 * `$event->commentedModel` is the model the comment was added to.
157
158 Possible use cases:
159
160 * Send an E-Mail-Notification
161
929699d @cebe add update action + events for upd/delete close #4
cebe authored
162 ### onUpdateComment
163
164 This event is raised when a user edited a comment.
165 The following attributes are available on the `$event` given as the first parameter to the event handler:
166
167 * `$event->comment` is the ActiveRecord instance of the updated comment.
168
169 ### onDeleteComment
170
171 This event is raised when a user deleted a comment.
172 The following attributes are available on the `$event` given as the first parameter to the event handler:
173
174 * `$event->comment` is the ActiveRecord instance of the deleted comment.
2a389bd @cebe added onNewComment-Event to CommentModule
cebe authored
175
Something went wrong with that request. Please try again.