Call a function from an anchor

#1
[eluser]Unknown[/eluser]
Hey Guys

Newbie here. I am trying to create a real basic web app using CI. I just followed Derek Jones Tutorial on building a basic blog. I would like to add the functionality for my own learning purposes of creating a basic delete comment function.

I would also like to have an anchor link on the comment page that deletes the comment?

How do I go about calling my delete_comment function from this anchor?

And what is the simplest way to build a delete function?

Thanks D :-)

#2
[eluser]GSV Sleeper Service[/eluser]
well, you could create a method in your blog controller called 'delete_comment'
eg
Code:
...
function delete_comment($comment_id){
//some code to delete the comment
}
[code]
to call this, you construct a link like
[code]
<a href="blog/delete_comment/[comment_id]">delete</a>
but deleting stuff via 'get' (not strictly 'get' in this case, but acts very much like it) is a bad idea, you should really be POSTing your data to delete things.

#3
[eluser]Unknown[/eluser]
Thanks. I will give that a go.

I am fairly new to PHP and CodeIgniter. You mentioned using POST. How would it be done using POST? If that is a better way then I would very much like to know how its done.

Thanks again

D :-)


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.