I am learning CodeIgniter. I am wondering which one is the best practice to get the form POST data when updating the database: from Controller or from Model?
If we get the POST data in the Controller, then we need to pass the data as arguments to the Model function, but the Model function can be used in other forms. If we get the POST data directly in the Model, then we can eliminate the argument passing step, but it's limited to some specific forms.
Which one is the best practice?
Thanks.
It is best practice to handle your view code (form responses, etc) in your controllers, and then pass anything you need as parameters to your models.
This allows for the most reuse, as your model (and it's methods) can be reused, if, for example, you have a different view and controller requiring that model which processes forms in different ways (e.g. an API).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With