Insert and update in the same view |
[eluser]Jonas G[/eluser]
This is how I do it: Controller add: Code: $data['action'] = 'add'; Controller edit: Code: $data['action'] = 'edit'; View: Code: <h1><?= ($action == 'add') ? 'Write a blog' : 'Edit blog' ?></h1> Please note that this is only part of the code. But I think it's enough for you to get the idea. Also, I'm quite new to codeigniter so if anyone can see a problem with this way of doing it please tell me. Oh, and by doing it this way you run into a bug in the form_validation library. See: http://ellislab.com/forums/viewthread/99760/ You can optimize this a little by replacing $action == 'add' with $add in all the ($action == 'add') statements
[eluser]il_dandi[/eluser]
Thanks for help me!! What do you have inserted in the model? ... simply the insert and update queries?? or other for manage insert/update in the same view... Why do you have $data['action'] = 'add'; $data['add'] = true; Can't you use only action or add for manage the "action": insert or update? Thanks
[eluser]Jonas G[/eluser]
I have a controller that looks something like this: Code: function blog($action=false, $id=false) I have both $data['action'] = 'add'; and $data['add'] = true; so I can do ($add) ? 'i add' : 'i edit' instead of doing ($action == 'add') ? 'i add' : 'i edit'. I just haven't gotten around to changing that in the view. I really should put the insert and update statements into models and if I did that I would put them in to different functions - if that answers your question. |
Welcome Guest, Not a member yet? Register Sign In |