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="generate2" 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

 

29 Comments

 

  1. August 15, 2009  5:21 pm by muhidin Reply

    tanks master...langsung josss..

  2. August 16, 2009  11:28 am by slash2x Reply

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

  3. September 4, 2009  5:13 pm by indra Reply

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

    ada dokumentasinya?

  4. October 6, 2009  10:57 am by arifdeni Reply

    thanks, nice post

  5. December 31, 2009  4:44 pm by ains Reply

    thanks gan..

  6. March 12, 2010  10:12 am by CS Org Sunda Reply

    Aduh ternyata masih banyak yang harus dipelajari, begini nih hasil dari belajar cuma setengah-setengah jadi tanggung, btw step by step using Jquery nya usefull banget, thanks

  7. March 23, 2010  6:53 am by zymanq Reply

    mangtabs.....

  8. May 21, 2010  4:37 pm by gufakto Reply

    numpang save page gan buat dipelajari hehehe.....

    thanks.....

    • May 21, 2010  5:07 pm by ibnoe Reply

      monggo ^^

  9. June 5, 2010  9:16 am by Ary Wibowo [at] nucreativa Reply

    bro, udah pernah nyoba pake yii framework blom? di yii jg gampang bgt pake jquery. coz ud integrate di dalam packagenya. dulu ane jg pake CI cm skr ganti ke Yii. sambil nunggu CI versi 2 :D

    • June 5, 2010  3:36 pm by ibnoe Reply

      Wah belum ne... bagi2 dong ilmunya.. :D

  10. June 18, 2010  8:12 pm by zalaz Reply

    di extractnya di /system/plugins/ ya ?? soalnya ga ada klo di application/plugins/

    Btw apa bedanya klo kita nyimpen folder jquery (beserta isinyee) di luar folder system/

    trus kita panggil pake

  11. June 18, 2010  8:13 pm by zalaz Reply

    di extractnya di /system/plugins/ ya ?? soalnya ga ada klo di application/plugins/

    Btw apa bedanya klo kita nyimpen folder jquery (beserta isinyee) di luar folder system/

    trus kita panggil dari file yang di folder views ??

  12. June 29, 2010  12:08 pm by Haqqi Reply

    Kalau pakai php apa nggak malah ribet?

    • June 29, 2010  2:23 pm by ibnoe Reply

      Tergantung.. kalo kita gunain php sebagai generatornya kayaknya makin lebih mempercepat

      • May 5, 2012  2:49 pm by cekibrot Reply

        etst

  13. July 6, 2010  11:59 am by daniel Reply

    allow ibnoe... sebelumnya thx bwt infonya gan.. hehehehe...
    ada tutorial nya atau materi selengkapnya gak ya?? aq lagi belajar bwt plugin dengan jquery juga... hehehehehehe.. khususnya buat nampilin animasi.. :p

  14. July 15, 2010  4:07 pm by user Reply

    keren mas2 web nya .... :)

  15. August 6, 2010  10:41 pm by dhemitlinux Reply

    He he he he,
    anchornya kok pake id yang sama sih mas? {id='generate'}
    dimana-mana, id itu kan harus unique di satu halaman html

  16. August 8, 2010  9:51 pm by ibnoe Reply

    @dhemitlinux
    hohoho Copas.. lupa ganti :D tq ya.. untuk saya pake selectornya class :D

  17. January 23, 2011  4:31 pm by jadul Reply

    keren bos. web showcase resmi pluginnya dmn tuh?

  18. April 19, 2011  11:00 am by aaa Reply

    coba

  19. June 24, 2011  2:36 pm by aris Reply

    terimakasih bnyk y om.... dh mau berbagi ilmu

    • June 30, 2011  9:31 pm by ibnoe Reply

      @aris.. sama2 om.. semoga bermamfaat

  20. September 19, 2011  2:07 pm by brooks defyance Reply

    Great site. Plenty of useful info here. I am sending it to some pals ans also sharing in delicious. And naturally, thanks for your effort!

  21. December 7, 2011  11:39 am by ariez_zip Reply

    kalau $ is not defined
    $("#category_id").change(function(){

    itu kurang diapanya ya ?

    • December 7, 2011  3:39 pm by ibnoe Reply

      Sepertinya library jquery belom di loaad dengan benar

  22. January 31, 2012  9:45 am by handy Reply

    kalau di Codeigniter 2.1.0 di extract nya di folder mana ya? soalnya gak ada pluginnya...thx bang ibnu

Leave a reply

 

Your email address will not be published.