Problem with edit data in db with form - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Problem with edit data in db with form (/showthread.php?tid=62105) |
Problem with edit data in db with form - StratoKyke - 06-10-2015 I'm creating an admin cp and at the time I values in db I want to print in a form and then modify them. I used this method to print: Model PHP Code: public function get_info() { PHP Code: class Setting extends MY_Controller { and view: PHP Code: {form url="acp/setting/edit" type=""} But now I would like to make sure you edit the data, and I'm using something like this Model PHP Code: public function edit_info() { I realize that having to specify an if for each individual field is very uncomfortable. There is a way to simplify everything as I did for the creation of the form? Maybe an array? that one side contains the name of the field and on the other the value changed? I do not know, give me a hand? RE: Problem with edit data in db with form - InsiteFX - 06-10-2015 PHP Code: $data = array( RE: Problem with edit data in db with form - StratoKyke - 06-10-2015 In this way I can use $data['site_name'] for example to include the $this->input->post('site_name', TRUE). It is true? But in my table db i have a field that contains the name then site_name etc. and in another the value, that is the content of input. So you'll need both variables so as I say, where is the name site_name go to change the value. RE: Problem with edit data in db with form - mwhitney - 06-10-2015 If I understand what you're trying to do, you could do something like this in your base model: PHP Code: <?php Then, in your individual models, you would set the properties accordingly, and override the prepData() method (calling the parent's prepData() method) to add any additional prep you need to perform on specific fields. The primary purpose of this is that you can pass the entire output of $this->input->post() into prepData() and it will only return the fields for the table specified in the model's $tableName property (minus any fields you wish to skip). For example, I might have some special handling in a model like this: PHP Code: public function prepData($postData) Then my controller might do something like this: PHP Code: // Assuming the model has a getValidationRules() method which returns an array RE: Problem with edit data in db with form - StratoKyke - 06-10-2015 Explain better my problem: I have several fields in the form that already contain within them the value of the corresponding tightening in the db table for example: In the db I have the name of input and the value. <input type="text" name="name of value" value="value of the db"/> This repeated for all values of the table. Now, what I want to achieve is that changing any of these inputs, or more than one. The value is updated in the table row correct. What I wonder is there a way to take from the input not only the value but also the name? That way I could make a query with a where and have solved the problem. No? |