Using CRUD with OO Models |
Hello All
I am following a tutorial at http://www.revillweb.com/tutorials/codei...0-minutes/ Could someone explain to me the best way to submit user data from the form to the database please? At the moment this is what i do... 1. controller collects all user data and sends it to UserFactory as an array 2. UserFactory creates a new user object with the data it receives and returns the object to the controller 3. controller then calls commit method of the user object using $user->commit() 4. the commit method of the user model creates an array from the users attributes and then inserts this array into the database using $data = array( 'username' => $this->_username, 'password' => $this->_password ); $this->db->insert("user", $data) Is this the right way to do it? It seems excessive to create an object from an array, call the commit method of the object and then create another array from the objects private members which is finally inserted into the database. I would love if you would comment and/or direct me to additional tutorials. PS I am using CI3 Thanks in advance
The described in the tutorial way works, but it seems to me time-consuming. Every CRUD-operated table would require a model and a library. Adding a field to some table would require lots of modifications. I have a project with about 80 tables (although not all of them are CRUD-operated)... this approach is not for me.
For my purposes I use a base model https://github.com/ivantcholakov/codeigniter-base-model that is a modified and CI3-updated clone of Jamie Rumbelow's one https://github.com/jamierumbelow/codeigniter-base-model Unfortunately I can not provide a tutorial. Edit: Anyway, see the trick "INPUT DATA FILTRATION BEFORE INSERT/UPDATE" in the home page of my project. It saves time. A side note: The password field (from the tutorial) should be hashed.
|
Welcome Guest, Not a member yet? Register Sign In |