Welcome Guest, Not a member yet? Register   Sign In
Insert data from a form into a db with MVC CodeIgniter
#1

[eluser]masentinel900[/eluser]
Hello everybody, In this time I want insert date from a form in a db using MVC CodeIgniter.
The view form content basically two inputs text and one input file, The Idea is mainly insert the inputs text in the adecuate rows and the file input save the file in a folder on the server and that upload the directory of the file..

Already I'have the script for the directory and functs good.

But I need to know how is the structure of the MVC using the "Form Helper".

I did saw that in the model file goes some like this:

Code:
$code = array(
'name' = $this->input->post('name'),
'lastanme' = $this->input->post('lastname'),
);
$this->db->insert('My_table', $code);

But I think this: If in the model file goes this script so what goes in the controller file?

Please someone that can help me.
#2

[eluser]Barwick[/eluser]
Is this a user generated date? If not, just use DATETIME in your database. It's what I'd do. Each entry will then be pegged with a time and date (i.e. "2012-12-31 23:59:59"). If it is user generated, just treat the value of the form input as you would any field.
#3

[eluser]Aken[/eluser]
Use your controller to gather the post values, and send that data to your model, which performs in the insert. That's how I do it. I personally don't recommend fetching input variables directly in the model.
#4

[eluser]masentinel900[/eluser]
[quote author="Mike Barwick" date="1351719626"]Is this a user generated date? If not, just use DATETIME in your database. It's what I'd do. Each entry will then be pegged with a time and date (i.e. "2012-12-31 23:59:59"). If it is user generated, just treat the value of the form input as you would any field.[/quote]

Hello how are you..

Excuseme maybe I didn' t knew express my ask.. Is not a date, is any data which I may insert in a DB through CodeIgniter.
I just want to know what is the better way for may insert "Data" in a DB.

This process is relatively easy with only PHP, But right now I´m learning CI because I believe that is a simply but powerfull framework.

Thanks by you response.


#5

[eluser]masentinel900[/eluser]
[quote author="Aken" date="1351747645"]Use your controller to gather the post values, and send that data to your model, which performs in the insert. That's how I do it. I personally don't recommend fetching input variables directly in the model.[/quote]

Hello, Many thanks by your opportune response, That were I would like to know, But now still I have a new question.

I saw in the user guide of CI that suggest by security way that is better work with the next structure:

Code:
$this->input->post('some_goes_here');

This looks easy, But would like to know what goes previous that, So. I need to call some library in this Controller file?. I know that in the view file goes the "<?php form_open?>"
for get the variables.

Will be that you can give a general example of this controller file. some short for to may direct better..

Appreciate many your help..
#6

[eluser]LuckyFella73[/eluser]
You really should get familiar with the CI user guide!
I promise you will some kind of love it as soon you
know where to look for getting the needed infos.

Back to your question - the user guide provides a tutorial
describing the whole process you are interested in:
http://ellislab.com/codeigniter/user-gui...index.html

That should give you a clue how to handle form submitting,
processing data to database and display db results in your view.




Theme © iAndrew 2016 - Forum software by © MyBB