Looping $_POST values into a CRUD Model - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Looping $_POST values into a CRUD Model (/showthread.php?tid=11798) |
Looping $_POST values into a CRUD Model - El Forum - 09-23-2008 [eluser]opel[/eluser] I have used PHP to handcode my own CMS but have been playing bout with CI. I am aware there are plenty of CRUD libraries out there but I am trying to create my own controllers/models to add/edit/delete data so that I can understand my app and CI before. I have tried to update my old class methods for insert and update into CI but I am not having much luck. What I am trying to do is take all the values of $_POST, unset the button value and then generate an array that I can use in AR to insert/update my db the code that I am trying below is loosing the "$this" part when I try to print_r as a test. Code: function process_add() { Could anyone give me any suggestions or point me in the way of a tutorial that may help? Looping $_POST values into a CRUD Model - El Forum - 09-24-2008 [eluser]Pascal Kriete[/eluser] It looks like all you're trying to do is copy the post array into your $data array. Why? They're going to be identical. You could just unset the value and continue using POST. Or copy the whole POST array and use the copy. I think what you're shooting for in the loop is this: Code: // old But once again, I don't see why you would do this. You could expand it to filter disallowed keys. That would be a good idea, and could be accomplished with a lot more precision and less code: Code: function _filter_input($allowed, $data) Then you can pass the $_POST array straight into the model. In the model you call said function: Code: function create($data) Let me know if that answered any part of your question . Looping $_POST values into a CRUD Model - El Forum - 09-24-2008 [eluser]opel[/eluser] I'll try it tonight and let you know how I get on, thanks for the advice? Looping $_POST values into a CRUD Model - El Forum - 09-24-2008 [eluser]opel[/eluser] I managed to convert all my old functions which work fine. Not sure the best way to make them available to all my models though My plan is to base a form on the add/edit example in the wiki where I have a "form" view and controller that processes add/edit functions and then use the crud functions of my model. Is the best practice to create my own "Crud_model" that extends the CI model and then subclass that for my app, i noticed helpers are only for views and controllers. My code at the moment is : Code: class Pages_model extends Model { |