CodeIgniter Forums
Bootstrap Modal (View, Edit, Delete) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Model-View-Controller (https://forum.codeigniter.com/forumdisplay.php?fid=10)
+--- Thread: Bootstrap Modal (View, Edit, Delete) (/showthread.php?tid=535)



Bootstrap Modal (View, Edit, Delete) - GrigoreMihai - 12-15-2014

I'm trying to add the basic CRUD function to models in bootstrap. Adding them in a foreach loop with primary key as ID's for models creates a loot of models and this is very bad practice. Is there a way to create only one model for each CRUD functions and send the data to it somehow ?


Any help is good. Thanks for your time.


RE: Bootstrap Modal (View, Edit, Delete) - InsiteFX - 12-15-2014

You can create a MY_Model and extend all your models from MY_Model

See the CI Users Guide on MY_Model


RE: Bootstrap Modal (View, Edit, Delete) - GrigoreMihai - 12-15-2014

(12-15-2014, 05:42 AM)InsiteFX Wrote: You can create a MY_Model and extend all your models from MY_Model

See the CI Users Guide on MY_Model

I know that I have did it for my CI models .. this is not that much related to CI but i posted here to in the hope someone did this before.. 
When i say model i was referring to bootstrap models ....


RE: Bootstrap Modal (View, Edit, Delete) - advoor - 12-15-2014

(12-15-2014, 06:00 AM)GrigoreMihai Wrote:
(12-15-2014, 05:42 AM)InsiteFX Wrote: You can create a MY_Model and extend all your models from MY_Model

See the CI Users Guide on MY_Model

I know that I have did it for my CI models .. this is not that much related to CI but i posted here to in the hope someone did this before.. 
When i say model i was referring to bootstrap models ....


I believe you are asking regarding http://getbootstrap.com/javascript/#modals  ?

My method to do this with as few lines of code is the following:

  1. Create a single modal for each CRUD
  2. For each item, loop with a foreach and output the buttons with the unique ID as a data attribute of the button
  3. Some JQuery to use the ID found to find the related information and then update the modal with the information

Here is a example code
Code:
$('.item-edit').on("click", function() {
    id = $(this).attr('data-item-id');
       option_text = $('span[data-option-text=' + id + ']').text();
      $('#create-modal-option-text').val(option_text);
});

For my data, I tend to put it in a span tag with data attributes but you can store the information in other places.


RE: Bootstrap Modal (View, Edit, Delete) - GrigoreMihai - 12-15-2014

(12-15-2014, 09:55 AM)advoor Wrote:
(12-15-2014, 06:00 AM)GrigoreMihai Wrote:
(12-15-2014, 05:42 AM)InsiteFX Wrote: You can create a MY_Model and extend all your models from MY_Model

See the CI Users Guide on MY_Model

I know that I have did it for my CI models .. this is not that much related to CI but i posted here to in the hope someone did this before.. 
When i say model i was referring to bootstrap models ....


I believe you are asking regarding http://getbootstrap.com/javascript/#modals  ?

My method to do this with as few lines of code is the following:


  1. Create a single modal for each CRUD
  2. For each item, loop with a foreach and output the buttons with the unique ID as a data attribute of the button
  3. Some JQuery to use the ID found to find the related information and then update the modal with the information

Here is a example code

Code:
$('.item-edit').on("click", function() {
    id = $(this).attr('data-item-id');
       option_text = $('span[data-option-text=' + id + ']').text();
      $('#create-modal-option-text').val(option_text);
});

For my data, I tend to put it in a span tag with data attributes but you can store the information in other places.

Will try it .. thanks for the info.