Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get POST data in controller or model

Tags:

codeigniter

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.

like image 786
Jason Avatar asked Jan 19 '23 08:01

Jason


1 Answers

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

like image 192
Emma Avatar answered Jan 25 '23 13:01

Emma