Welcome Guest, Not a member yet? Register   Sign In
Separating Code / Error Handling
#1

[eluser]Unknown[/eluser]
I am new to CodeIgniter but am having this problem quite a bit. Say I have a controller 'Contacts' and the index() page lists all the contacts... and on this same page I want to have a form to add a contact... The only thing I can do (If I want to print validation errors), is to handle the form in the same controller...

Is there a way of making a new method in the controller... add_contact().. handling the form in that then passing the errors back to the index() controller? Or is this just not a good idea?
#2

[eluser]wh1tel1te[/eluser]
Sure, there is no reason why you can't handle the form validation in another method. In your index() method, just call the add_contact() method, which will return your errors. If you don't want people to be able to access "index.php/contacts/add_contact", you can add an underscore before the "add_contact" method to make it private, so it becomes "_add_contact()".
#3

[eluser]Unknown[/eluser]
Ahh fantastic (: thanks. I didn't realise you could use _ to stop direct access.
#4

[eluser]InsiteFX[/eluser]
The _method in CodeIgniter makes that method private.

You can also do $_var_name

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB