Look for some good Javascript class examples in CodeIgniter

I find it hard to understand how to use the javascript class in CodeIgniter 2.

What I would like to see is a good use of jquery loading, binding to selectors, ajax, and finally ... Using this in a template system that uses a single header.

Any good pointers or examples are appreciated.

+3
source share
1 answer

you can create header.phpin your view, on your controller you will need to call

<?php

class Page extends CI_Controller {

   function index()
   {
      $data['page_title'] = 'Your title';
      $this->load->view('header');
      $this->load->view('content', $data);
      $this->load->view('footer');
   }

}
?>

You will need a header and footer for each controller you create,

on you header.phpOR footer.phpdepends on how you want to use your javascript ...

<script src="[jquery url]"></script>
<script src="">
   $(document).ready(){
       $('div').hide(2500);
       $('a').click(function (){
            $('p').load('ajax');
       });
   });
</script>

content.php

<div>I will hide away soon enough (~2.5 seconds)</div>
<a href="#">Click Here</a>
<p>Your ajax content will go here once you click link above</p>

====== ajax

<?php

class Page extends CI_Controller {

   function ajax()
   {
      $json['error'] = '';
      $json['error'] = '';
      echo json_encode($json);
     /// or if you want html back//
      $data['page_title'] = 'Your title 2';
      $this->load->view('ajax', $data);//ajax.php on your view
   }

}
?>

ajax.php -, ...

-2

All Articles