2
votes

Hi I'm trying to use the CakePHP comments plugin found here http://cakedc.com/downloads/view/cakephp_comments_plugin but the instructions are really hard to follow. I've managed to add comments but it's displaying the commentWidget that's not working.

I'm getting confused at this part i think

To work properly, the component needs a specific variable to be set in every action using it. Its name should be either Inflector::variable(Controller::$modelClass) or Comments::$viewVariable should be set to other name of this view variable. That variable should contain single model record. for example you need to have next line in you view

So far I've created the comments table, added it to the pluging and components arrays and added the following code to the controller:

public function beforeFilter() {        
    parent::beforeFilter();     
    $this->passedArgs['comment_view_type'] = 'flat';
}

I added the route

Router::connectNamed(array('comment', 'comment_view', 'comment_action));

And also the Comments.CommentWidget as a helper in my controller.

I'm just wondering if anyone has used this plugin before and can help me out?

thanks,

Jonesy

1

1 Answers

1
votes

You're right - the documentation is really confusingly worded. However, if I understand correctly, what it wants is a copy of the record of the piece of data the comment will be attached to passed to the view the comments will render on.

So say you're making an event page, and you want people to comment on the event. You need to send to the view a variable called "event" with a copy of the base data for that event.

From their example they show: $this->set('post', $this->Post->read(null, $id));

For your event, you'd do something like $this->set('event', $this->Event->read(null, $id_of_event));

The Comment view probably needs this data for hidden fields so it can populate it with the model name and the event id.