• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Separating Code / Error Handling

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?

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()".

Ahh fantastic (: thanks. I didn't realise you could use _ to stop direct access.

The _method in CodeIgniter makes that method private.

You can also do $_var_name


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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