Welcome Guest, Not a member yet? Register   Sign In
Where to collect data from forms(controller or model)
#1

[eluser]max123[/eluser]
what is the best thing to collect data from forms. Inside the controller or a model

eg: $this->input->post('firstName');

where to put this. Inside the controller or a model?
#2

[eluser]maria clara[/eluser]
in the controller. for example:

$data = $this->input->post('firstName');

$this->db->insert('<table_name>', $data); //note that <table_name> is where you put your data in the database.

P.S.
just an opinion..it still up to where you will put your code.

regards,
maria Wink
#3

[eluser]Colin Williams[/eluser]
It really depends on what your doing, but I don't think I've run across many cases where I need to access it in my Models
#4

[eluser]vitoco[/eluser]
I think that you ( and i ) must do it in the controller, cause the form data must be validated before send it to the model, and this one only retrieve data according to the parameters ( form data ) or in another case, perform INSERT, DELETES or UPDATES.
#5

[eluser]Jamie Rumbelow[/eluser]
I generally get all input in the controller layer - it makes a lot more sense to me to get it in the controller and pass through to the model. Having said that, sometimes it's just cleaner and nicer to put it in the model. Skinny controllers, fat models. Ultimately, it's personal preference.

Jamie
#6

[eluser]theprodigy[/eluser]
I collect it in the controller, myself. That way, the controller decides what gets sent to what model. You may have a form that needs to access several models for either a select query, insert query, etc. The controller will take the form submission, then send the correct data to the correct model.

You can also use the controller to validate and/or modify the submitted data prior to sending it to the model.
#7

[eluser]Colin Williams[/eluser]
theprodigy, I would still put more burden on the model for manipulating the data. The model API should be really flexible and smart. It should know the data better than anyone. Letting the model validate (or at least provide the rules) makes sense in a lot of occasions too.




Theme © iAndrew 2016 - Forum software by © MyBB