Search code examples
jquerycodeignitermodal-dialogsimplemodal

Codeigniter and eric martin simplemodal


I'm am trying to implement eric martin's simplemodal into my Codeigniter project. So far all I can get it to do is give me a 404 page not found in Firebug. I'm using the modal to alert users they are being redirected from my site to a 3rd party web site. I grab the url from the my link href to use as the link in the modal so users can continue.

My thoughts were that the Jquery would catch the /depart/ and use the appropriate controller and load the proper view into the modal. It doesn't seem to work that way. Firebug is showing the response as a 404. I tried adding a custom route to the routes file to handle the many different link possiblities, but this had no effect. How should I be approaching this?

Jquery

var OSX = {
      container: null,
      init: function () {
          $('.depart').click(function (e) {
              e.preventDefault();
              var myid = $(this).attr('href');
              $.get("/depart/" + encodeURIComponent(myid), function(data){
                  $(data).modal({
                      opacity: 65,
                      overlayClose: true,
                      onOpen: OSX.open
                  });
              });
          });
      },
      open: function (d) {
          var self = this;
          self.container = d.container[0];
          d.overlay.fadeIn('slow', function () {
              $("#depart", self.container).show();
              d.container.fadeIn('slow', function () {
                  d.data.fadeIn('slow');
              });
          });
      }
  };
  OSX.init();
});

Link

a class="depart" href="http://www.newwebsite.com"


Solution

  • So, this is what I came up with that seems to work. I updated the jQuery .get to include a url= parameter. Then let Codeigniter get that variable in the controller. If the variable is set and the link exists in the database the user may then proceed exiting the site by clicking the link.

    jQuery

    $.get("/depart/?url=" + encodeURIComponent(myid), function(data){
    

    Controller index method

    $url = $this->input->get('url');
    $this->data['continue'] = isset($url]) && $this->links_model->check_link($url) == TRUE ? '<a href="'.$url.'">Continue</a>' : '<a href="">Continue</a>'; 
    

    This stackoverflow question helped me find my way, Passing URL in Codeigniter URL segment