Model/Controller Quick Question |
[eluser]ikim[/eluser]
Hi, Im starting to learn how to keep all database stuff inside models and separate it from the controllers. However, Ive been looking around and I cant seem to understand how to insert data into the database. Right now I have a small form in my view sending the form to the controller. Code: function insert() and then the model has Code: function insert_info() What am I missing? Ive been reading the user quide and trying to find something on the forum but I cant seem to find anything. Thanks for the help
[eluser]kgill[/eluser]
Couple of quick thoughts since you didn't post any error messages, have you loaded the database class? CI's default configuration doesn't load it automatically. Second point, you're setting the data but you aren't actually calling the insert() method in active record. Go back and take another look at the user guide's active record stuff - there's enough examples there to get you where you want to go. And just a comment, dumping the post vars straight into the DB like that is generally not the best idea if you're concerned about security. - K
[eluser]Christopher Blankenship[/eluser]
Ok. putting my two cents into the mix. Here is what I like to do to avoid all those $_POST statements. Code: /* controller: add_task */ Code: $autoload['libraries'] = array('database');
[eluser]Bulk[/eluser]
Take another look - you're not using the database functions properly - you seem to be cofusing the set function with insert. Also as previously mentioned dumping POST variables direct in to a database is very bad form - you should look at the input class functions // Edit: didn't read the rest of the thread properly, kgill said most of what I said
[eluser]Christopher Blankenship[/eluser]
I agree with Bulk, passing post variables directly into a database is bad form; if you intend the application to be for anything other than a quick and dirty example (which I apologize for) or in this case a task management system for myself which is not accessible by anyone but myself. So to that end: Code: /* controller: add_task_rec Code: /* controller: add_task_rec |
Welcome Guest, Not a member yet? Register Sign In |