Welcome Guest, Not a member yet? Register   Sign In
Bootstrap Modal (View, Edit, Delete)
#1

(This post was last modified: 12-15-2014, 04:56 AM by GrigoreMihai.)

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.
Reply
#2

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

See the CI Users Guide on MY_Model
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(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 ....
Reply
#4

(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.
Reply
#5

(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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB