CodeIgniter Forums
Send data from DB to bootstrap modal's - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Send data from DB to bootstrap modal's (/showthread.php?tid=897)



Send data from DB to bootstrap modal's - GrigoreMihai - 01-27-2015

I want to ask what is the best way to send data to a modal-body. Lets say i have a link like :

Code:
<a href="#" data-toggle="modal" data-target=".bs-example-modal">Test </a>

and then the bootstrap modal :

Code:
<div class="modal fade bs-example-modal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
          <div class="modal-content">
               <div class="modal-header">
                    <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                    <h4 id="myLargeModalLabel" class="modal-title">Test</h4>
               </div>
                                           
               <div class="modal-body">
                    
                     contect here !!

               </div>
                                           
               <div class="modal-footer">
                     <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
               </div>
           </div>
     </div>
   

Now adding then with different ID's its very bad since this will create a loot of modal's and that is just bad codding...
I have read a loot of variables on how to get the data by aJax but still not that sure on how to do it.
If anyone was some time for a explanation fell free to post.


Thanks for your time.


RE: Send data from DB to bootstrap modal's - Rufnex - 01-27-2015

You can use jquery for this task

PHP Code:
<a href="#" id="modal-trigger" data-toggle="modal" data-target=".bs-example-modal">Test </a>

$(
'#modal-trigger').click(function(){
    $(
'.modal-title').html('your title ...');
    $(
'.modal-body').html('your content <strong>goes here</strong>!');
}); 

You have to extend the example, to pass the different content dynamicly to the modal template.


RE: Send data from DB to bootstrap modal's - CroNiX - 01-27-2015

You can use ajax to retrieve the content from a controller that will go in the modal when you click to open the modal. Then set the content of the modal like Rufnex mentioned above. You can use a single modal for everything on the page instead of multiple.


RE: Send data from DB to bootstrap modal's - GrigoreMihai - 01-28-2015

Thanks for the help ... Since im new to bootstrap modals i want to ask is there a way to create a folder modals in the view and add modals there for lets say CRUD .. then when needed load the modal view and send data to it ? This seams to me to be the best way to work with bootstrap modals and ci.