Insert and Edit with CodIgniter

1

In reality it is not a question but rather if you can give me some direction to take on a subject.

I took a project to fix and the developer used CodeIgniter, but the project is quite large and we have several files.

The big problem is that for each Product, Category, User, etc. the developer created a view to edit the data (edit_user.php) and a page to insert a new user (new_user.php), what is the difference between two:

The only difference is that in the first view the INPUT fields have the value ( $user[0]->txtNome and in the second view the value fields are blank

The problem with this is that if I change or insert a field for the user, I have to change both pages, too much work.

One solution would be to put an IF on all inputs, but this could get huge, depending on the amount of form fields.

Another output would be to create an objet with the name of all fields and assign the value equal to NULL, which would look great too.

The question is:

  • Is there any way in CodeIgniter to create this dynamically, ie using a set_fields, creating an empty object, etc.

I would not like to use Dynamic CRUD like GROCERY, so if anyone has any suggestions or a direction they could give me, I appreciate everyone's help

    
asked by anonymous 13.02.2015 / 15:18

1 answer

1

Friend, since you're using Codeigniter, I do not know if there is an effective solution in it. Maybe there's some library or helper that can help you.

But I believe that you can solve this problem simply by using a isset , through ternary condition, to know if it will print or not.

If your form looks like this:

<input name="nome" value="<?= $dados->nome ?>">

You can simply do one of the options below

<input name="nome" value="<?= isset($dados->nome) ? $dados->nome : null ?>" >

<input name="nome" value="<?php isset($dados->nome) and print $dados->nome ?>" >

I think editors like Sublime Text could help make this change faster.

    
13.02.2015 / 15:29