jQuery-PHP Codeigniter Pluggin

Posted on August 15th, 2009 in Blog by ibnoe Discuss this article »

jquery-php jQuery-PHP adalah sebuah PHP library yang memunggkinkan kita untuk mengitegrasikan syntax jQuery di PHP. Jika menggunakan Codeigniter maka salah satu cara yang dapat kita lakukan adalah dengan menuliskan kode jquery didalam view. atau jika ingin menyimpannya sebagai variable string di controller.

Liat contoh kode dibawah ini, itu adalah controller yang dapat memanipulasi halaman web menggunakan syntax jquery di php.
Untuk demo anda bisa lihat disini

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * jquery_php class
 *
 * @package default
 * @author Ibnu Daqiqil Id
 **/
 
class jquery_php extends Controller 
{
 
	function __construct()
	{
		parent::__construct();
	}
 
	/**
	 * Index function
	 *
	 * @return void
	 * @author Ibnu Daqiqil Id
	 **/	
	function index()
	{
		$this->load->view('jquery_client');
	}
 
	function backend()
	{
		$this->load->plugin('jquery');
		jQuery('#home')->html(date('Y-m-d h:m:s').' - Hellow World!!');
		jQuery::getResponse();
	}
	function backend2()
	{
		$this->load->plugin('jquery');
		jQuery('#home')->html(date('Y-m-d h:m:s').' - Hellow World!!')->css('backgroundColor' , '#ff0000');
		//jQuery::evalScript("alert('aaa')");
		jQuery::addAction('click',"alert('aaa')");
		jQuery::getResponse();
	}
 
	function backend_event()
	{
		$this->load->plugin('jquery');
		jQuery('#home')->html(date('Y-m-d h:m:s').' - <a id="a" href="#"> Hellow World!!</a>')->css('backgroundColor' , '#ff0000');
 
	//	$('#loading').slideDown('fast');
 
	}
 
}
 
// END  jquery_php class
 
/* End of file jquery.php */
/* Location: /Applications/XAMPP/xamppfiles/htdocs/riset/application/controllers/jquery.php  */

Sedangkan untuk viewnya

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/2002/REC-xhtml1-20020801/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>jQuery PHP - Codeigniter library</title>
    <meta name="keywords" content="php, ajax, jquery, javascript" />
    <meta name="description" content="jQuery PHP library" />
    <script src="<?=base_url()?>/jquery-1.3.2.js" type="text/javascript"></script>
 
    <script src="<?=base_url()?>jquery.php.pack.js" type="text/javascript"></script>
    <script src="<?=base_url()?>jquery.form.js" type="text/javascript"></script>
	<script type="text/javascript">
 
		$(document).ready(function()
		{
	    	$(".ajax").click(function(){
			 	$.php(this.href);
				return false;
			});
 
	  	});
 
	</script>
	<style>
	.output{
		border: 1px #000 solid;
		backgound-color:#ccc;
	}
	</style>
</head>
<body>
<script language="JavaScript" type="text/javascript">
 
formAjax = function () {
    $.php(url, $('form#form').formToArray(true));
    return false;
}
</script>
<!-- start header -->
<h1>Demo Jquery Client</h1>
<a id="generate" href="<?=site_url('jquery_php/backend')?>" class="ajax">Running</a><br>
<code>
	jQuery('#home')->html(date('Y-m-d h:m:s').' - Hellow World!!');
</code>
<br>
<a id="generate" href="<?=site_url('jquery_php/backend2')?>" class="ajax">Running</a><br>
<code>
	jQuery('#home')->html(date('Y-m-d h:m:s').' - Hellow World!!')->css('backgroundColor' , '#ff0000');;
</code>
 
 
OUTPUT:
<div id="home" class="output"> &nbsp;</div>
</body>
</html>

Download Jquery-PHP Pluggin

Installasi

1. Extract file di application/plugins/
2. Load pluggin tersebut




Artikel yang berhubungan

5 Responses Add your own

  1. muhidin says:

    tanks master…langsung josss..

  2. slash2x says:

    nais inpo gan… ini dia yg gw cari2… :thumbup:

  3. indra says:

    “mengitegrasikan syntax jQuery di PHP”
    berarti syntax tetep berupa PHP ya bos?
    tadinya kukira untuk mengincludekan jquery

    ada dokumentasinya?

  4. arifdeni says:

    thanks, nice post

  5. ains says:

    thanks gan..

Leave a Reply