Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter - Bootstrap Modal - passing data

I am pretty new to Codeigniter and aiming to follow best practice as I learn. Currently I have a table that is generated via DB

HTML Table

<tr>
    <td>
      <a class="galName" href="#myModal" data-toggle="modal" >
        <?php echo $gal['name']; ?>
      </a>
    </td>
    <td>
      <?php echo $gal['clientName']; ?>
    </td>
</tr>
<?php endforeach; ?>

The Modal

<div class="modal fade hide modal-creator" id="myModal" style="display: none;" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">×</button>
        <h3>Edit Gallery</h3>
    </div>
    <div class="modal-body"><?php echo form_open('url'); ?>

    <div class="row">
        <div class="span5">
            <?php print_r($galleryName); ?>
            <div class="control-group">
                <?php
                    $galleryName = array(
                        'id'            => 'galleryName',
                        'name'          => 'galleryName',
                        'placeholder'   => 'Gallery Name',
                        'required'      => 'required',
                    );
                    echo form_label('Gallery Name:', 'galleryName');
                    echo form_input($galleryName);
                ?>
            </div><!-- /control-group -->
       </div><!--/span5-->
   </div><!--/row-->
</div><!-- /modal-body -->

<div class="modal-footer">
    <!-- <p class="span3 resize">The following images are sized incorrectly. Click to edit</p> -->
    <a href="javascript:;" class="btn" data-dismiss="modal">Close</a>
    <a href="javascript:;" class="btn btn-primary">Next</a>
</div>

The link calls a bootstrap modal where I want to pass the data for the selected gallery. I know that I can pass the data via jQuery, but is it possible to keep this modal in the MVC framework and if yes how does one go about calling the controller via the modal link?

Thanks so much on the help, and would be happy to accept any suggestions on resources for CodeIgniter. I am currently working through the Nettuts videos, though they are dated,and also working through the user guide.

like image 535
SuperNinja Avatar asked Oct 06 '22 18:10

SuperNinja


1 Answers

i really think you are misunderstanding what modal is and what a controller is, you can't do this without ajax call: how does one go about calling the controller via the modal link

what i usually do is to create a view/modals/ folder then put there all my bootstrap modals so for example:

application/views/modals/my_modal_form.php

and that will looks as you shown, inside:

<div class="modal fade hide modal-creator" id="myModal" style="display: none;" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">×</button>
        <h3>Edit Gallery</h3>
    </div>
    <div class="modal-body"><?php echo form_open('url'); ?>

    <div class="row">
        <div class="span5">
            <?php print_r($galleryName); ?>
            <div class="control-group">
                <?php
                    $galleryName = array(
                        'id'            => 'galleryName',
                        'name'          => 'galleryName',
                        'placeholder'   => 'Gallery Name',
                        'required'      => 'required',
                    );
                    echo form_label('Gallery Name:', 'galleryName');
                    echo form_input($galleryName);
                ?>
            </div><!-- /control-group -->
       </div><!--/span5-->
   </div><!--/row-->
</div><!-- /modal-body -->

<div class="modal-footer">
    <!-- <p class="span3 resize">The following images are sized incorrectly. Click to edit</p> -->
    <a href="javascript:;" class="btn" data-dismiss="modal">Close</a>
    <a href="javascript:;" class="btn btn-primary">Next</a>
</div>

so when i need that single modal i just load it inside the main controller view i want to show up that modal doing simply:

    <body>
    <?php echo $this->load->view('modals/my_modal_form'); ?>

    <tr>
    <td>
      <a class="galName" href="#myModal" data-toggle="modal" >
        <?php echo $gal['name']; ?>
      </a>
    </td>
    <td>
      <?php echo $gal['clientName']; ?>
    </td>
</tr>
<?php endforeach; ?>
    </body>
like image 136
itsme Avatar answered Oct 09 '22 17:10

itsme