-
Notifications
You must be signed in to change notification settings - Fork 4
Comment
reillyethan edited this page Feb 16, 2015
·
12 revisions
Comment module is used (obviously) for commenting specific entities. Let's look how it works.
- Open your app in browser and go to
dashboard - Choose
Comment -> Write Comments.
Yes, but this is disabled by default (for a lot of reasons). To enable this feature:
- Go to a
dashboardand chooseComment -> Create entity - Create an entity with alias comment and choose Comment\Entity\Comment. Also mark all fields checked to enable visibility and possibility to comment. From this moment all your comments will have a button Answer, try it!
1. Go to a `dashboard` `Comment -> Create entity` and create an entity based on your custom made one. So you need to give it an _alias_ and choose it from the _list of entities_. Then mark needed options as checked.
2. Create an object of your Entity (e.g. add a new row to a table in your db).
3. Create a controller for displaying this entity, and pass it to a viewmodel with `Comment\Service\Comment`
$commentService = $this->getServiceLocator()->get('Comment\Service\Comment'); 3.1 Also, pass to a view an array of comments using this service
$comments = $commentService->treeByEntity($entity); //$entity is an object of your entity 3.2 Then we need to check if comments are visible for your `$entityType`. You must get
$entityType->isVisible()4. In a view somehow display this entity (if you want, of course) and generate a form for entering comments using method from `$commentService`:
$commentService->getAddCommentForm($commentService->createForm(), $entityId, $entityAlias);5. Display comments using view helper
if ($comments && is_array($comments) && count($comments)) {
echo $this->comment($comments);
};That's all, pretty simple, ha!