On Sun, Oct 24, 2010 at 1:02 PM, iamjonesy <billyjone...@googlemail.com> wrote: > Hi, > > I'm trying to use the cake comments plugin found here - > http://cakedc.com/downloads/view/cakephp_comments_plugin I'm having > trouble though. I can add comments - it captures datetime, userid, > etc, etc. but it just doesn't display the comments in the widget. I've > added it to the controller's plugins and components arrays, unzipped > the plugin to the plugins folder and added the beforeFilter function. > > I put > > <div id="project-comments"> > <?php $commentWidget->options(array('allowAnonymousComment' => > false));?> > <?php echo $commentWidget->display();?> > </div> > > in my view. It displays everything apart from the comments that are > added. So it lets me type a title and a body. I save the comment, get > a session flash saying comment displayed, look at the comments table > and see the comment in there but it's just not displayed in the > widget.
I was looking at this plugin last week and found several problems with it. The first, glaring, issue is that the requirements only mention Cake 1.3.x. However, if you look at the controller, you'll see that it expects your User model to come from some mysterious User plugin. Not especially portable, this. There were also several things that just seemed badly thought out. Although I'll admit that some may simply be due to my not understanding the code. There are several things about it that are pretty confusing. Not least of which is the documentation, which is riddled with incomplete sentences. I should mention that I was looking at it because I was interested in writing my own. The problems that I found, though, didn't keep me from borrowing a few ideas. But mine definitely takes a different approach (and is also not ready for Primetime). > I got confused here so skipped it: > > 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 action: > > > $this->set('post', $this->Post->read(null, $id)); > What this is saying is that, in your controller, you must either name your data variable (whatever contains your, eg. Post data) to the equivalent of Inflector::variable(YourModel) (eg. Post -> $post) or tell the component what the variable name is. That is, if you prefer to do: $data = $this->Post->find(...) ... then you should set $viewVariable to 'data'. You can either do this when declaring the component, or in beforeFilter() public $components = array( 'Comments.Comment' => array( 'viewVariable' => 'data' ) ); OR: function beforeFilter() { parent::beforeFilter(); $this->Comments->viewVariable = 'data'; } Or, because the component doesn't actually use it until your controller has done it's find, you could set this in your individual actions. Or, as mentioned, you can ignore it if you prefer to name your data variable after the model. Just be sure to use Inflector::variable(YourModelName). The component sets it to this by default in startup(). Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en