Welcome Guest, Not a member yet? Register   Sign In
Editing a form - CI strategy
#5

[eluser]NemetraL[/eluser]
[quote author="thepyromaniac" date="1187883484"]
That's one way but if you find you are making way to make if statements to check if its add or edit, try using totally different methods. You will find yourself using some repeated code but as time goes on you will find it more manageable as you can add in bits and take bits out without worrying about the affect on the other.

You can still use the same view doing it this way. I just output a variable like:

Code:
$data['form_action'] = 'add';
// or
$data['form_action'] = 'edit/'.$itemID;
[/quote]

Personnally I prefer to create only one edit function that will add a new item if called like that:

Code:
http://www.website.com/controller/edit

... and edit a specific item (here: id 42) if called like that:

Code:
http://www.website.com/controller/edit/42

Inside the controller, a simple if() statement can distinguish between the two cases by analyzing $this->uri->segment(3);

In the model, either I create two function, or one with the same if() calling either a
Code:
SQL INSERT INTO
or a
Code:
SQL UPDATE

For basic CRUD, that's incredibly time-saving.

@stevefink: in your particular case, you will need the two model functions and you will do different checkings in each one of them. This way you'll keep a common controller, a common view and, still, two different behaviours.


Messages In This Thread
Editing a form - CI strategy - by El Forum - 08-22-2007, 09:09 PM
Editing a form - CI strategy - by El Forum - 08-22-2007, 11:17 PM
Editing a form - CI strategy - by El Forum - 08-23-2007, 04:38 AM
Editing a form - CI strategy - by El Forum - 08-23-2007, 05:30 PM
Editing a form - CI strategy - by El Forum - 08-24-2007, 11:18 AM
Editing a form - CI strategy - by El Forum - 08-27-2007, 04:24 PM
Editing a form - CI strategy - by El Forum - 08-27-2007, 04:31 PM
Editing a form - CI strategy - by El Forum - 08-27-2007, 04:35 PM



Theme © iAndrew 2016 - Forum software by © MyBB