Welcome Guest, Not a member yet? Register   Sign In
Writing a comments system - any good structuring tips?
#1

[eluser]mattpointblank[/eluser]
Hi everyone.

I've just spent quite a long time coding up a commenting function for my site. At the moment, the program flow is like this:

- Comment box appears underneath article
- If the user is not logged in, fields for their name/email are displayed
- When the user submits the comment, they are either asked to log in (if the email address they enter is already in the user table), at which point they're returned to the comment page with the textarea prepopulated with their comment.
- If their email address isn't in the system, they're asked to register, then returned to the comment page, again with the comment prepopulated.
- If they're logged in, the comment is posted right away.

I initially had all of the logic for this plugged into my article controller. I felt this was messy and also, wasn't extendable to other controllers where I might want users to be able to comment. I stripped all the code out and put it in a 'comments' controller. I then pointed the comment form action to comment/add, which runs the above code.

My issue now is that the data-specific details aren't being passed once the form is submitted. I call comment form view inside my article controller, and pass it the data from the article (eg the article ID, as a hidden form input, so we know what content the comment is associated with). Once I submit the form, I move from article/view/123/ to /comment/add and then when the form is validated, I lose the article data. Is there some way I can keep this data around without keeping all of the comment code within the article controller?

Thanks
Matt
#2

[eluser]TheFuzzy0ne[/eluser]
Hi, Matt.

I can't see the problem here, perhaps you need to post some code? I'd suggest that if you want any part of the code to be re-used, that you export it to a library.
#3

[eluser]tomcode[/eluser]
Do You do a redirect() somewhere ? If yes, You loose the post data. You can use flash data to tunnel the data.




Theme © iAndrew 2016 - Forum software by © MyBB