how to add a controller function to approve comments??
I'm working on a basic website based on cakephp and already have comments working, I added a field to the database which defaults to 0, which means the comment has not been approved yet, so I've added a moderate function to the comments controller showing all the comments which haven't been moderated yet. My question is, how do I update the field (set it to 1) by clicking a link (comments/approve/$id), I know how to save the data but only with a new, separate view. What I need is to approve a comment simply by clicking the url and then going back to the same moderation page. I think this should be a simple question, I've googled and searched this group and the cakephp site but couldn't find anything so I hope you can answer my question, thanks in advance! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: how to add a controller function to approve comments??
The simplest way is to have the approve method, when called: - perform the DB update, - set a flash message, - redirect back to the originating page (the refferer, usually available in a controller via the referrer() method). You should also make the links mini forms that do HTTP POST requests rather than GET requests, to prevent against amateur URL hacking, etc. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: how to add a controller function to approve comments??
Thank you, I've managed to make it work using the code below: function approve($id) { $this-Comment-id = $id; if($this-Comment-saveField('visible',1)) $this-flash('This comment has been approved','/comments/ moderate'); } I'm not sure about the mini forms for security you're talking about, could you give an example or explain it?? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: how to add a controller function to approve comments??
Sorry, I should have been clearer - I'm just referring to you using a HTTP GET request to call the approve function, rather than a POST using a html form. It's no big deal :) Also, fyi, you can also use the Session component to redirect to a pge and have the flash message appear on that page, rather than the 'see a message, wait for redirect; functionality that you get from the flash method you're currently using. Just some food for thought... Wood On Feb 25, 6:43 pm, jelmer [EMAIL PROTECTED] wrote: Thank you, I've managed to make it work using the code below: function approve($id) { $this-Comment-id = $id; if($this-Comment-saveField('visible',1)) $this-flash('This comment has been approved','/comments/ moderate'); } I'm not sure about the mini forms for security you're talking about, could you give an example or explain it?? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---