0

I want to edit record in cakephp for that i want to load modal popup that is placed inside another view edit.ctp. There is a page view.ctp where user can click link on a link and modal popup will show up. I need a different view for my modalpopup. Below is code.Please help to solve my issue. If i place my modal on the same page i.e. view.ctp it is working but i need a different view.

view.ctp

<li>
   <?php              
       echo $this->Html->link("Edit Profucts","/PanelAdmin/products/edit/".$prod->product_id, array('update' => '#flexModal','id'=>'flexModal','data-target' => 'flexModal','htmlAttributes' => array('data-toggle' => 'modal',)));
    ?>
 </li>

    <script>
    $(document).ready(function() {
       $("a[data-target='flexModal']").click(function(ev) {
           ev.preventDefault();
           var target = $('#flexModal').attr("href");
           $("#flexModals .modal-body").load(target, function(data) {
               $("#flexModals").modal("show");
           });
        });
    });
    </script>

edit.ctp

<div class="modal" data-target="#flexModal" tabindex="-1" role="dialog" data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3 class="modal-title" id="myModalLabel"></h3>
            </div>
            <div class="modal-body">


            <?php 

            echo $products->product_name;
            echo $products->product_desc;

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

ProductsController.php

public function edit($id)
{
    $products = $this->Products->get($id);
     $this->set(compact('products'));
}
user3653474
  • 3,393
  • 6
  • 49
  • 135
  • put the modal code in [element](https://book.cakephp.org/3.0/en/views.html#elements) then in edit.ctp or view.ctp just called that element – shahonseven Nov 30 '17 at 13:18
  • @shahonseven: how will i call modal with ajax or there is some other concept in cakephp, because i did'nt know much in cakephp, that is confusing for me and i have found this link but it does not work http://www.anjuke.tech/questions/4940844/cakephp-implement-modal-window-for-edit – user3653474 Nov 30 '17 at 13:32
  • correct me if I'm wrong, it seems you want to load a view into modal using ajax? if so check this answer out - https://stackoverflow.com/questions/18378720/bootstrap-3-with-remote-modal – shahonseven Nov 30 '17 at 13:35
  • Yes it will also work for me is there any link to achieve that in cakephp. Only thing i want to do is to give user to edit in modal pop up. – user3653474 Nov 30 '17 at 13:41
  • Cake3 doesn't have any JavaScript helper; the required output depends very much on what JS library you might be using, and supporting even the popular ones in a generic way proved unworkable. You might be able to find third-party plugins that you can install and use for this purpose. – Greg Schmidt Dec 02 '17 at 02:32

0 Answers0